Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Pass back real result for single task chains #6411

Merged
merged 1 commit into from Oct 14, 2020

Conversation

maybe-sybr
Copy link
Contributor

Description

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 a chain has a single
task, we pass back the result object constructed when the task was
actually applied. When that single child is a group which does not get
unrolled (ie. contains more than one child itself), this ensures that we
pass back a GroupResult object which will actually be fulfilled. The
caller can then await the result confidently!

@maybe-sybr
Copy link
Contributor Author

This change is the one I mentioned I would pull out of #6354 - FYI @auvipy . I believe the changeset here will also address your coverage comment on that PR.

@maybe-sybr
Copy link
Contributor Author

Ah, I need to pull one of the integrations tests across from that PR as well. This is the change that makes it not time out!

@lgtm-com
Copy link

lgtm-com bot commented Oct 14, 2020

This pull request fixes 1 alert when merging 8b4250d into 735f167 - view on LGTM.com

fixed alerts:

  • 1 for Module is imported with 'import' and 'import from'

celery/canvas.py Outdated Show resolved Hide resolved
Copy link
Member

@thedrow thedrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an integration test for this?

@maybe-sybr
Copy link
Contributor Author

Can we add an integration test for this?

Yep, test_nested_chain_group_lone() is the one which demonstrates the fix. The other is just a sanity check for simple groups since there wasn't one in the suite.

@lgtm-com
Copy link

lgtm-com bot commented Oct 14, 2020

This pull request introduces 1 alert when merging f0242da into 735f167 - view on LGTM.com

new alerts:

  • 1 for Non-exception in 'except' clause

@auvipy auvipy added this to the 5.0.1 milestone Oct 14, 2020
auvipy
auvipy previously approved these changes Oct 14, 2020
Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apart from the better naming, looks good

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 a chain has a single
task, we pass back the result object constructed when the task was
actually applied. When that single child is a group which does not get
unrolled (ie. contains more than one child itself), this ensures that we
pass back a `GroupResult` object which will actually be fulfilled. The
caller can then await the result confidently!
@maybe-sybr
Copy link
Contributor Author

I went with result_from_apply and also changed the results returned from self.prepare_steps() to be results_from_prepare. That should make it more obvious, and with the block comment explaining why we should return the one _from_apply I think it's nice and readable :)

@auvipy auvipy merged commit 9367d36 into celery:master Oct 14, 2020
@maybe-sybr maybe-sybr deleted the maybe/fix-chain-group-tails branch October 14, 2020 08:33
@maybe-sybr
Copy link
Contributor Author

Thanks @auvipy and @thedrow :)

@lgtm-com
Copy link

lgtm-com bot commented Oct 14, 2020

This pull request introduces 1 alert when merging bd6c6bd into 735f167 - view on LGTM.com

new alerts:

  • 1 for Non-exception in 'except' clause

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants