Browse Source

Prevent ResultSet from invoking backend.remove_pending_result (fixes #4539) (#4540)

* Prevent ResultSet from invoking backend.remove_pending_result in favour of GroupResult

* Add's test to ensure that ResultSet.get operates correctly

* Fix flake warnings and errors in test_canvas
Derek Harland 7 years ago
parent
commit
e3b973d90d
3 changed files with 17 additions and 3 deletions
  1. 2 1
      CONTRIBUTORS.txt
  2. 4 1
      celery/result.py
  3. 11 1
      t/integration/test_canvas.py

+ 2 - 1
CONTRIBUTORS.txt

@@ -257,4 +257,5 @@ Mikhail Wolfson, 2017/12/11
 Alex Garel, 2018/01/04
 Régis Behmo 2018/01/20
 Igor Kasianov, 2018/01/20
-Chris Mitchell, 2018/02/27
+Derek Harland, 2018/02/15
+Chris Mitchell, 2018/02/27

+ 4 - 1
celery/result.py

@@ -487,7 +487,6 @@ class ResultSet(ResultBase):
                 self._on_full.add(result)
 
     def _on_ready(self):
-        self.backend.remove_pending_result(self)
         if self.backend.is_async:
             self._cache = [r.get() for r in self.results]
             self.on_ready()
@@ -845,6 +844,10 @@ class GroupResult(ResultSet):
         self.parent = parent
         ResultSet.__init__(self, results, **kwargs)
 
+    def _on_ready(self):
+        self.backend.remove_pending_result(self)
+        ResultSet._on_ready(self)
+
     def save(self, backend=None):
         """Save group-result for later retrieval using :meth:`restore`.
 

+ 11 - 1
t/integration/test_canvas.py

@@ -7,7 +7,7 @@ import pytest
 
 from celery import chain, chord, group
 from celery.exceptions import TimeoutError
-from celery.result import AsyncResult, GroupResult
+from celery.result import AsyncResult, GroupResult, ResultSet
 
 from .conftest import flaky, get_redis_connection
 from .tasks import (add, add_chord_to_chord, add_replaced, add_to_all,
@@ -186,6 +186,16 @@ class test_chain:
         assert result == 10
 
 
+class test_result_set:
+
+    @flaky
+    def test_result_set(self, manager):
+        assert manager.inspect().ping()
+
+        rs = ResultSet([add.delay(1, 1), add.delay(2, 2)])
+        assert rs.get(timeout=TIMEOUT) == [2, 4]
+
+
 class test_group:
 
     @flaky