Skip to content

Commit 73c50e4

Browse files
tothegumpOmer Katz
authored andcommitted
Pass parameters to the first task in chain().apply_async(params) (celery#4690)
Fixes celery#4643
1 parent 27d17c7 commit 73c50e4

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

celery/canvas.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ def run(self, args=(), kwargs={}, group_id=None, chord=None,
569569
if args and not self.immutable else self.args)
570570

571571
tasks, results = self.prepare_steps(
572-
args, self.tasks, root_id, parent_id, link_error, app,
572+
args, kwargs, self.tasks, root_id, parent_id, link_error, app,
573573
task_id, group_id, chord,
574574
)
575575

@@ -589,12 +589,12 @@ def freeze(self, _id=None, group_id=None, chord=None,
589589
# pylint: disable=redefined-outer-name
590590
# XXX chord is also a class in outer scope.
591591
_, results = self._frozen = self.prepare_steps(
592-
self.args, self.tasks, root_id, parent_id, None,
592+
self.args, self.kwargs, self.tasks, root_id, parent_id, None,
593593
self.app, _id, group_id, chord, clone=False,
594594
)
595595
return results[0]
596596

597-
def prepare_steps(self, args, tasks,
597+
def prepare_steps(self, args, kwargs, tasks,
598598
root_id=None, parent_id=None, link_error=None, app=None,
599599
last_task_id=None, group_id=None, chord_body=None,
600600
clone=True, from_dict=Signature.from_dict):
@@ -632,7 +632,10 @@ def prepare_steps(self, args, tasks,
632632

633633
# first task gets partial args from chain
634634
if clone:
635-
task = task.clone(args) if is_first_task else task.clone()
635+
if is_first_task:
636+
task = task.clone(args, kwargs)
637+
else:
638+
task = task.clone()
636639
elif is_first_task:
637640
task.args = tuple(args) + tuple(task.args)
638641

t/unit/tasks/test_canvas.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def test_group_to_chord(self):
333333
self.add.s(30)
334334
)
335335
c._use_link = True
336-
tasks, results = c.prepare_steps((), c.tasks)
336+
tasks, results = c.prepare_steps((), {}, c.tasks)
337337

338338
assert tasks[-1].args[0] == 5
339339
assert isinstance(tasks[-2], chord)
@@ -347,7 +347,7 @@ def test_group_to_chord(self):
347347

348348
c2 = self.add.s(2, 2) | group(self.add.s(i, i) for i in range(10))
349349
c2._use_link = True
350-
tasks2, _ = c2.prepare_steps((), c2.tasks)
350+
tasks2, _ = c2.prepare_steps((), {}, c2.tasks)
351351
assert isinstance(tasks2[0], group)
352352

353353
def test_group_to_chord__protocol_2__or(self):
@@ -372,7 +372,7 @@ def test_group_to_chord__protocol_2(self):
372372

373373
c2 = self.add.s(2, 2) | group(self.add.s(i, i) for i in range(10))
374374
c2._use_link = False
375-
tasks2, _ = c2.prepare_steps((), c2.tasks)
375+
tasks2, _ = c2.prepare_steps((), {}, c2.tasks)
376376
assert isinstance(tasks2[0], group)
377377

378378
def test_apply_options(self):

0 commit comments

Comments
 (0)