Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10698 +/- ##
==========================================
- Coverage 89.85% 89.85% -0.01%
==========================================
Files 153 153
Lines 20707 20709 +2
Branches 2473 2474 +1
==========================================
+ Hits 18607 18608 +1
Misses 1801 1801
- Partials 299 300 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
please also add smoke test for this.... and if possible integration test as well. @MehrazRumman can you also try it?
aeb9484 to
9cd0ed1
Compare
This comment was marked as spam.
This comment was marked as spam.
There was a problem hiding this comment.
Thanks @simpleqt, and thanks for adding the smoke and integration tests. The canvas fix is correct. The main issue is the branch itself.
Blocking: the branch includes the unrelated forget() commit
This PR also contains 4eb1c57 ("fix(backends): keep forget() idempotent on elasticsearch and couchdb"), which is the whole of #10697. It touches celery/backends/couchdb.py, celery/backends/elasticsearch.py and their tests. It looks like this branch was created from the #10697 branch instead of from main. Could you rebase onto main so the PR only contains 9cd0ed1? For example: git rebase --onto origin/main 4eb1c5771 chord-stamp-body. Otherwise, merging this would also merge #10697 without its own review, and it would conflict or duplicate whichever of the two lands second.
The canvas fix
The change makes _chord.stamp() follow the same pattern as Signature.stamp(), _chain.stamp() and group.stamp(): always call _stamp_headers(), and only call the visitor hook when a visitor is given. Before this, a chord was the only canvas type whose stamping skipped part of the canvas when visitor=None.
I compared main and this branch using chord(group(add.s(1, 1), add.s(2, 2)), xsum.s()):
| Case | main body custom |
this PR body custom |
|---|---|---|
c.stamp(custom='a') |
None |
'a' (same as header) |
stamp 'a', then stamp(append_stamps=True, custom='b') |
None |
['b', 'a'] (same as header) |
stamp 'a', then stamp(custom='b') |
None |
'b' (same as header) |
chord inside group(...), group stamped |
None |
'g' |
chord inside chain(...), chain stamped |
None |
'ch' |
In every case the body now ends up with exactly what the header tasks get, including stamped_headers and the append_stamps behaviour, which is what I'd expect.
Worth noting in the changelog
As the last two rows show, the change isn't limited to calling chord.stamp() directly. Any chord nested in a group or chain stamped without a visitor now gets its body stamped as well. I think that's correct and consistent, but code that currently relies on the callback not carrying those stamps (for example, routing or monitoring that treats stamped messages differently) will behave differently after upgrading. A one-line changelog entry would help.
Tests
test_stamp_without_visitor_stamps_bodyfails onmainand passes here. That's the key regression test.test_stamp_with_visitor_stamps_bodyalready passes onmain, since the visitor path always stamped the body. That's fine as a guard, but maybe say so in a docstring so nobody expects it to cover the fix.test_stamped_chord_applies_end_to_end_without_visitoronly checks thatapply()still returns12. It doesn't check that the body received the stamp at execution time. Using a bound body task that recordsself.request.stampswould turn it into an actual end-to-end check of the fix. Otherwise the integration test is the only runtime check.- It would be good to add unit tests for the two cases above that aren't covered yet:
append_stamps=True(body matches header) and a chord nested in a stampedgroup/chain(body gets stamped). - Integration test: the
@task_received.connecthandler follows the pattern the other stamping tests in this class use, so that's fine as is.
Summary
The fix is correct and I'd approve it once the branch is rebased to remove the #10697 commit. Additional unit tests for append_stamps and nested chords, would be nice to have.
|
now this has merged conflicts so the unrelated commit must be discarded from this branch, along with additional tests and docs updates |
_Chord.stamp() guarded the body stamping behind visitor is not None, so a plain chord(header, body).stamp(custom=x) stamped every header task but silently dropped the stamps from the body. Stamping without a visitor is a documented, supported mode (Signature.stamp falls back to set(**headers)), and the header/body asymmetry meant callers could not rely on custom headers reaching the callback. Stamp the body whenever it exists; the visitor's on_chord_body hook is only consulted when a visitor was passed, preserving the visitor flow covered by the existing stamping tests. Signed-off-by: simpleqt <[email protected]>
cf77c99 to
24e34e4
Compare
Problem
_Chord.stamp()requires avisitorfor the body to receive any stamps:Stamping without a visitor is a supported public mode —
Signature.stampdocuments plain custom-header stamping and falls back toset(**headers)— and inside_Chord.stamp()the header tasks are stamped unconditionally. Only the final body block was additionally guarded withvisitor is not None, producing a header/body asymmetry: custom headers (routing keys, trace metadata, monitoring tags) reach the header tasks but never the callback.With a visitor the body is stamped today, so the guard only breaks the non-visitor flow.
Fix
Stamp the body whenever it exists; consult
visitor.on_chord_body()only when a visitor was passed:Tests
test_stamp_without_visitor_stamps_body— plainstamp(custom=...)must land on the header tasks and the body (red before the fix: body options empty).test_stamp_with_visitor_stamps_body— guards the visitor flow (green before and after).Red/green verified: with the fix reverted the non-visitor test fails and the visitor test passes; with the fix all 258 tests in
t/unit/tasks/test_canvas.pyplustest_stamping.py+test_chord.py(461 tests, 27.6k subtests) pass.pre-commit run --files(pinned hooks incl. flake8/isort/mypy) passes on both changed files.