← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~ack/maas:piston-0.5-on-3.2 into maas:3.2

 

Alberto Donato has proposed merging ~ack/maas:piston-0.5-on-3.2 into maas:3.2.

Commit message:
backport changes for piston 0.5

5b79ab7e5 - bump piston dependency, drop now useless monkeypatch
4117bcf3b - drop monkeypatch for piston emitter, since it's been fixed in piston itself


Requested reviews:
  Alberto Donato (ack)

For more details, see:
https://code.launchpad.net/~ack/maas/+git/maas/+merge/437512
-- 
Your team MAAS Committers is subscribed to branch maas:3.2.
diff --git a/debian/control b/debian/control
index e1376d9..01078b9 100644
--- a/debian/control
+++ b/debian/control
@@ -80,7 +80,7 @@ Depends: bind9 (>= 1:9.10.3.dfsg.P2-5~),
          python3-bson,
          python3-django (>= 2:2.2),
          python3-django-maas (= ${binary:Version}),
-         python3-django-piston3 (>= 0.4),
+         python3-django-piston3 (>= 0.5.1),
          python3-maas-provisioningserver (= ${binary:Version}),
          python3-macaroonbakery (>= 1.2.1),
          python3-mimeparse,
diff --git a/src/maasserver/monkey.py b/src/maasserver/monkey.py
index ba4629f..523a159 100644
--- a/src/maasserver/monkey.py
+++ b/src/maasserver/monkey.py
@@ -7,7 +7,6 @@ Monkey patch for the MAAS region server, with code for region server patching.
 
 
 from collections import OrderedDict
-import inspect
 
 from twisted.web import http
 import yaml
@@ -45,46 +44,6 @@ def fix_django_deferred_attribute():
     DeferredAttribute.__get__ = DeferredAttributePreventer__get__
 
 
-def fix_piston_emitter_related():
-    """Fix Piston so it uses cached data for the `_related`.
-
-    Piston emitter code is all one large function. Instead of including that
-    large chunk of code in MAAS to fix this one issue we modify the source of
-    the function and re-evaluate it.
-
-    The `_related` function uses `iterator` which skips precached relations,
-    changing it to `all` provides the same behaviour while using the precached
-    data.
-    """
-    from piston3 import emitters
-
-    bad_line = "return [_model(m, fields) for m in data.iterator()]"
-    new_line = "return [_model(m, fields) for m in data.all()]"
-
-    try:
-        source = inspect.getsource(emitters.Emitter.construct)
-    except OSError:
-        # Fails with 'could not get source code' if its already patched. So we
-        # allow this error to occur.
-        pass
-    else:
-        if source.find(bad_line) > 0:
-            source = source.replace(bad_line, new_line, 1)
-            func_body = [line[4:] for line in source.splitlines()[1:]]
-            new_source = ["def emitter_new_construct(self):"] + func_body
-            new_source = "\n".join(new_source)
-            local_vars = {}
-            exec(new_source, emitters.__dict__, local_vars)
-            emitters.Emitter.construct = local_vars["emitter_new_construct"]
-
-
-def fix_piston_consumer_delete():
-    """Fix Piston so it doesn't try to send an email when a user is delete."""
-    from piston3 import signals
-
-    signals.send_consumer_mail = lambda consumer: None
-
-
 def fix_ordereddict_yaml_representer():
     """Fix PyYAML so an OrderedDict can be dumped."""
 
@@ -128,7 +87,5 @@ def fix_twisted_disconnect_write():
 def add_patches():
     add_patches_to_twisted()
     fix_django_deferred_attribute()
-    fix_piston_emitter_related()
-    fix_piston_consumer_delete()
     fix_ordereddict_yaml_representer()
     fix_twisted_disconnect_write()

References