Skip to content

fix(canvas): add group index when unrolling tasks#8427

Merged
Nusnus merged 2 commits intocelery:mainfrom
backmarket-oss:fix/add-group-index-when-unrolling-tasks
Aug 7, 2023
Merged

fix(canvas): add group index when unrolling tasks#8427
Nusnus merged 2 commits intocelery:mainfrom
backmarket-oss:fix/add-group-index-when-unrolling-tasks

Conversation

@mkniewallner
Copy link
Copy Markdown
Contributor

Note: Before submitting this pull request, please review our contributing
guidelines
.

Description

Fixes #8421.

As mentioned in the linked issue, since Celery 5.3.0, tasks results in chord are not received by the callback in the same order as the tasks were created. This can be seen in backmarket-oss#1 that adds a test asserting the order. The root cause seems to be the removal of an apparently useless zip on results here. While removing it is a good call, the zip actually meant that we executed the generator, effectively setting group_index to retrieve the results in the correct order.

Although I wasn't sure where exactly would be the best place to fix the issue, I noticed that we could also set group_index while unrolling the tasks in a group, effectively setting the correct order for the results, while keeping all tests green. This was made after an initial workaround in https://github.com/backmarket-oss/celery/pull/2 that was more a way to show the side effect that running the generator behind results had than a real attempt to fix the issue.

I'm still not sure at this point if this is a proper way to fix the issue, so if you have other ideas in mind, I'm all ears.

This integration test ensures that tasks results are received in the
same order as they were created when received by the callback.
When using `chord`, tasks results are not received in the order they
were created. Setting the group index when unrolling tasks ensure that
it is the case.
@codecov
Copy link
Copy Markdown

codecov bot commented Aug 7, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (87b3617) 87.42% compared to head (dbb26a0) 87.42%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8427   +/-   ##
=======================================
  Coverage   87.42%   87.42%           
=======================================
  Files         148      148           
  Lines       18477    18477           
  Branches     3153     3153           
=======================================
  Hits        16153    16153           
  Misses       2034     2034           
  Partials      290      290           
Flag Coverage Δ
unittests 87.38% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
celery/canvas.py 97.44% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Nusnus Nusnus self-requested a review August 7, 2023 19:09
Copy link
Copy Markdown
Member

@Nusnus Nusnus left a comment

Choose a reason for hiding this comment

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

Well done! 💯
✅ High quality PR
✅ Thorough investigation
✅ Elegant fix + automatic test

Thank you for your contribution!

@Nusnus Nusnus merged commit ef50442 into celery:main Aug 7, 2023
@mkniewallner mkniewallner deleted the fix/add-group-index-when-unrolling-tasks branch August 8, 2023 09:05
mkniewallner added a commit to backmarket-oss/celery that referenced this pull request Aug 11, 2023
* test(integration): add test to assert `chord` order

This integration test ensures that tasks results are received in the
same order as they were created when received by the callback.

* fix(canvas): add group index when unrolling tasks

When using `chord`, tasks results are not received in the order they
were created. Setting the group index when unrolling tasks ensure that
it is the case.
mkniewallner added a commit to backmarket-oss/celery that referenced this pull request Aug 11, 2023
* test(integration): add test to assert `chord` order

This integration test ensures that tasks results are received in the
same order as they were created when received by the callback.

* fix(canvas): add group index when unrolling tasks

When using `chord`, tasks results are not received in the order they
were created. Setting the group index when unrolling tasks ensure that
it is the case.
mkniewallner added a commit to backmarket-oss/celery that referenced this pull request Aug 11, 2023
* ci: remove codecov

* ci: run `python-package` on all PR branches

* fix(canvas): add group index when unrolling tasks (celery#8427)

* test(integration): add test to assert `chord` order

This integration test ensures that tasks results are received in the
same order as they were created when received by the callback.

* fix(canvas): add group index when unrolling tasks

When using `chord`, tasks results are not received in the order they
were created. Setting the group index when unrolling tasks ensure that
it is the case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[5.3.0] Task results order is not preserved anymore

2 participants