Skip to content

Commit ddb2985

Browse files
committed
fix: Pass back real result for single task chains
When chains are delayed, they are first frozen as part of preparation which causes the sub-tasks to also be frozen. Afterward, the final (0th since we reverse the tasks/result order when freezing) result object from the freezing process would be passed back to the caller. This caused problems in signaling completion of groups contained in chains because the group relies on a promise which is fulfilled by a barrier linked to each of its applied subtasks. By constructing two `GroupResult` objects (one during freezing, one when the chain sub-tasks are applied), this resulted in there being two promises; only one of which would actually be fulfilled by the group subtasks. This change ensures that in the special case where the final task of a chain is a group, we pass back the `GroupResult` object constructed when the group was actually applied. The caller can then await the result confidently!
1 parent e4c8929 commit ddb2985

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

celery/canvas.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,16 @@ def run(self, args=None, kwargs=None, group_id=None, chord=None,
662662
first_task = tasks.pop()
663663
options = _prepare_chain_from_options(options, tasks, use_link)
664664

665-
first_task.apply_async(**options)
666-
return results[0]
665+
real_result = first_task.apply_async(**options)
666+
# If we only have a single task, it may be important that we pass
667+
# the real result object rather than the one obtained via freezing.
668+
# e.g. For `GroupResult`s, we need to pass back the result object
669+
# which will actually have its promise fulfilled by the subtasks,
670+
# something that will never occur for the frozen result.
671+
if not tasks:
672+
return real_result
673+
else:
674+
return results[0]
667675

668676
def freeze(self, _id=None, group_id=None, chord=None,
669677
root_id=None, parent_id=None, group_index=None):

0 commit comments

Comments
 (0)