Browse Source

Fix current_app fallback in GroupResult.restore() (#4431)

Alex Hill 7 years ago
parent
commit
973bb1875f
2 changed files with 12 additions and 2 deletions
  1. 4 2
      celery/result.py
  2. 8 0
      t/unit/tasks/test_result.py

+ 4 - 2
celery/result.py

@@ -895,8 +895,10 @@ class GroupResult(ResultSet):
     @classmethod
     def restore(cls, id, backend=None, app=None):
         """Restore previously saved group result."""
-        app = app or cls.app
-        backend = backend or (app.backend if app else current_app.backend)
+        app = app or (
+            cls.app if not isinstance(cls.app, property) else current_app
+        )
+        backend = backend or app.backend
         return backend.restore_group(id)
 
 

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

@@ -658,6 +658,14 @@ class test_GroupResult:
         restored = GroupResult.restore(ts.id, app=self.app)
         assert restored.id == ts.id
 
+    def test_restore_current_app_fallback(self):
+        subs = [MockAsyncResultSuccess(uuid(), app=self.app)]
+        ts = self.app.GroupResult(uuid(), subs)
+        ts.save()
+        with pytest.raises(RuntimeError,
+                           message="Test depends on current_app"):
+            GroupResult.restore(ts.id)
+
     def test_join_native(self):
         backend = SimpleBackend()
         results = [self.app.AsyncResult(uuid(), backend=backend)