Browse Source

Fix append to an empty chain. Fixes #4047. (#4402)

This bug is a regression from Celery 3.x. A test was added to ensure no further regressions will occur.
Omer Katz 7 years ago
parent
commit
f148709062
2 changed files with 12 additions and 2 deletions
  1. 2 2
      celery/canvas.py
  2. 10 0
      t/unit/tasks/test_canvas.py

+ 2 - 2
celery/canvas.py

@@ -417,13 +417,13 @@ class Signature(dict):
             return sig
         elif isinstance(other, Signature):
             if isinstance(self, _chain):
-                if isinstance(self.tasks[-1], group):
+                if self.tasks and isinstance(self.tasks[-1], group):
                     # CHAIN [last item is group] | TASK -> chord
                     sig = self.clone()
                     sig.tasks[-1] = chord(
                         sig.tasks[-1], other, app=self._app)
                     return sig
-                elif isinstance(self.tasks[-1], chord):
+                elif self.tasks and isinstance(self.tasks[-1], chord):
                     # CHAIN [last item is chord] -> chain with chord body.
                     sig = self.clone()
                     sig.tasks[-1].body = sig.tasks[-1].body | other

+ 10 - 0
t/unit/tasks/test_canvas.py

@@ -469,6 +469,16 @@ class test_chain(CanvasCase):
             seen.add(node.id)
             node = node.parent
 
+    def test_append_to_empty_chain(self):
+        x = chain()
+        x |= self.add.s(1, 1)
+        x |= self.add.s(1)
+        x.freeze()
+        tasks, _ = x._frozen
+        assert len(tasks) == 2
+
+        assert x.apply().get() == 3
+
 
 class test_group(CanvasCase):