Skip to content

Commit af50b74

Browse files
committed
apply_async of empty chain must return None. Closes celery#1650
1 parent 1d12b0f commit af50b74

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

celery/canvas.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,16 @@ def set_immutable(self, immutable):
209209
self.immutable = immutable
210210

211211
def apply_async(self, args=(), kwargs={}, **options):
212+
try:
213+
_apply = self._apply_async
214+
except IndexError: # no tasks for chain, etc to find type
215+
return
212216
# For callbacks: extra args are prepended to the stored args.
213217
if args or kwargs or options:
214218
args, kwargs, options = self._merge(args, kwargs, options)
215219
else:
216220
args, kwargs, options = self.args, self.kwargs, self.options
217-
return self._apply_async(args, kwargs, **options)
221+
return _apply(args, kwargs, **options)
218222

219223
def append_to_list_option(self, key, value):
220224
items = self.options.setdefault(key, [])

celery/tests/tasks/test_canvas.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ def test_apply(self):
220220
self.assertEqual(res.parent.parent.get(), 8)
221221
self.assertIsNone(res.parent.parent.parent)
222222

223+
def test_empty_chain_returns_none(self):
224+
self.assertIsNone(chain(app=self.app)())
225+
self.assertIsNone(chain(app=self.app).apply_async())
226+
223227
def test_call_no_tasks(self):
224228
x = chain()
225229
self.assertFalse(x())

0 commit comments

Comments
 (0)