Repository navigation
fix(canvas): fire task lifecycle hooks for map/starmap items - #10880
Open
Sanjays2402 wants to merge 1 commit into
Open
Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
The celery.map and celery.starmap builtin tasks executed each item by calling the task directly, bypassing the task trace entirely. Task lifecycle hooks (before_start/on_success/on_failure/after_return) and task signals never fired for mapped items, unlike single tasks. Route every item through Task.apply() so the trace runs per item. get(disable_sync_subtasks=False) is safe here because the EagerResult is already computed and never blocks. Fixes celery#7585
auvipy
self-requested a review
October 18, 2026 03:57
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10880 +/- ##
==========================================
- Coverage 90.58% 90.57% -0.01%
==========================================
Files 153 153
Lines 21447 21447
Branches 2633 2633
==========================================
- Hits 19427 19426 -1
Misses 1707 1707
- Partials 313 314 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #7585
Fixes #7586
The
celery.mapandcelery.starmapbuiltin tasks ran each item by calling the task instance directly (task(item)/task(*item)), which skips the task trace completely. That meansbefore_start,on_success,on_failureandafter_returnnever fired for mapped items, and task signals were never sent, even though all of them fire for the same task executed on its own.chunksis affected too since it fans out throughxstarmap.The fix routes every item through
Task.apply()so each one gets a full trace..get(disable_sync_subtasks=False)is safe here: theEagerResultis already computed, so it never blocks, and passingFalsekeeps this working inside real workers where the join guard is on. Exceptions still propagate out of the map task exactly as before, and nowon_failurefires for them.Repro (before the fix,
map apply hookswas[]):Tests: added regression tests in
t/unit/app/test_builtins.pycovering hook order per mapped item formapandstarmap, pluson_failurefiring when an item raises. Rant/unit/app/test_builtins.py,t/unit/tasks/test_canvas.py,t/unit/app/test_trace.py,t/unit/tasks/test_result.py,t/unit/tasks/test_tasks.py: 638 passed, 1 skipped, 1 xfailed, all green.Also fixes #7586:
autoretry_forwas ignored for mapped items because the retry logic lives in the trace path. Verified: a task withautoretry_for=(ValueError,)andmax_retries=3raised after a single attempt throughmapbefore this change; now each item retries independently.