Explorar el Código

Fixed #3651 - add `app` argument to `GroupResult.restore`. (#3669)

This makes the restore method behave the same way as the `GroupResult`
constructor.
Andreas Pelme hace 8 años
padre
commit
a35e58cf92
Se han modificado 2 ficheros con 13 adiciones y 2 borrados
  1. 5 2
      celery/result.py
  2. 8 0
      t/unit/tasks/test_result.py

+ 5 - 2
celery/result.py

@@ -867,10 +867,13 @@ class GroupResult(ResultSet):
         return self.results
 
     @classmethod
-    def restore(cls, id, backend=None):
+    def restore(cls, id, backend=None, app=None):
         """Restore previously saved group result."""
+
+        app = app or cls.app
+
         return (
-            backend or (cls.app.backend if cls.app else current_app.backend)
+            backend or (app.backend if app else current_app.backend)
         ).restore_group(id)
 
 

+ 8 - 0
t/unit/tasks/test_result.py

@@ -19,6 +19,7 @@ from celery.result import (
     AsyncResult,
     EagerResult,
     ResultSet,
+    GroupResult,
     result_from_tuple,
     assert_will_not_block,
 )
@@ -615,6 +616,13 @@ class test_GroupResult:
         with pytest.raises(AttributeError):
             self.app.GroupResult.restore(ts.id, backend=object())
 
+    def test_restore_app(self):
+        subs = [MockAsyncResultSuccess(uuid(), app=self.app)]
+        ts = self.app.GroupResult(uuid(), subs)
+        ts.save()
+        restored = GroupResult.restore(ts.id, app=self.app)
+        assert restored.id == ts.id
+
     def test_join_native(self):
         backend = SimpleBackend()
         results = [self.app.AsyncResult(uuid(), backend=backend)