Skip to content

docs: clarify after_return behavior for retried tasks#10192

Merged
auvipy merged 4 commits into
celery:mainfrom
KianAnbarestani:docs/clarify-after-return
Mar 12, 2026
Merged

docs: clarify after_return behavior for retried tasks#10192
auvipy merged 4 commits into
celery:mainfrom
KianAnbarestani:docs/clarify-after-return

Conversation

@KianAnbarestani

Copy link
Copy Markdown
Contributor

Summary

This PR clarifies the documented behavior of after_return.

The previous wording could be interpreted as if after_return runs for every task attempt. In practice, it runs when the task reaches a terminal state and does not run for RETRY, REJECTED, or IGNORED.

The docs now also reference task_postrun for cases where a hook is needed on every attempt.

Reason

This aligns the documentation with the current behavior and avoids implying a potentially backward-incompatible behavior change.
Related discussion: #10046

@auvipy
auvipy requested a review from Copilot March 11, 2026 18:21
@auvipy auvipy added this to the 5.7.0 milestone Mar 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Clarifies Celery’s user documentation around when Task.after_return runs, specifically to avoid implying it executes on every retry attempt, and points readers to task_postrun for per-attempt hooks.

Changes:

  • Update the task lifecycle diagram caption to indicate after_return() runs only for terminal outcomes.
  • Clarify in the “Key points” section that after_return does not run for RETRY, REJECTED, or IGNORED.
  • Expand the after_return handler reference docs to reiterate the above and suggest task_postrun for every-attempt hooks.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread docs/userguide/tasks.rst
Comment thread docs/userguide/tasks.rst
@auvipy
auvipy requested a review from Copilot March 11, 2026 18:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


You can also share your feedback on Copilot code review. Take the survey.

Comment thread docs/userguide/tasks.rst Outdated
Comment thread docs/userguide/tasks.rst Outdated
@KianAnbarestani
KianAnbarestani requested a review from auvipy March 12, 2026 13:55
@auvipy
auvipy merged commit 309fd71 into celery:main Mar 12, 2026
6 checks passed
Nusnus pushed a commit that referenced this pull request Mar 26, 2026
* docs: clarify after_return behavior for retried tasks

* Update docs/userguide/tasks.rst

* docs: clarify after_return ordering for terminal states

---------

Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <[email protected]>
Nusnus pushed a commit that referenced this pull request Mar 26, 2026
* docs: clarify after_return behavior for retried tasks

* Update docs/userguide/tasks.rst

* docs: clarify after_return ordering for terminal states

---------

Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <[email protected]>
Nusnus pushed a commit that referenced this pull request Mar 26, 2026
* docs: clarify after_return behavior for retried tasks

* Update docs/userguide/tasks.rst

* docs: clarify after_return ordering for terminal states

---------

Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <[email protected]>
736-c41-2c1-e464fc974 pushed a commit to Swiss-Armed-Forces/Loom that referenced this pull request Mar 29, 2026
This MR contains the following updates:

| Package | Type | Update | Change | OpenSSF |
|---|---|---|---|---|
| [celery](https://docs.celeryq.dev/) ([source](https://github.com/celery/celery), [changelog](https://docs.celeryq.dev/en/stable/changelog.html)) | dependencies | patch | `5.6.2` → `5.6.3` | [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/celery/celery/badge)](https://securityscorecards.dev/viewer/?uri=github.com/celery/celery) |

---

### Release Notes

<details>
<summary>celery/celery (celery)</summary>

### [`v5.6.3`](https://github.com/celery/celery/releases/tag/v5.6.3)

[Compare Source](celery/celery@v5.6.2...v5.6.3)

#### What's Changed

- Fix Django worker recursion bug + defensive checks for pool\_cls.**module** by [@&#8203;maycuatroi1](https://github.com/maycuatroi1) in [#&#8203;10048](celery/celery#10048)
- Docs: Update user\_preload\_options example to use click. by [@&#8203;jorsyk](https://github.com/jorsyk) in [#&#8203;10056](celery/celery#10056)
- Fix invalid configuration key "bootstrap\_servers" in Kafka demo by [@&#8203;jorsyk](https://github.com/jorsyk) in [#&#8203;10060](celery/celery#10060)
- Fix broken images on PyPI page by [@&#8203;Timour-Ilyas](https://github.com/Timour-Ilyas) in [#&#8203;10066](celery/celery#10066)
- Remove broken reference. by [@&#8203;sueannioanis](https://github.com/sueannioanis) in [#&#8203;10071](celery/celery#10071)
- Removed --dist=loadscope from smoke tests by [@&#8203;Nusnus](https://github.com/Nusnus) in [#&#8203;10073](celery/celery#10073)
- Docs: Clarify task\_retry signal args may be None by [@&#8203;GangEunzzang](https://github.com/GangEunzzang) in [#&#8203;10076](celery/celery#10076)
- Update example for Django by [@&#8203;sbc-khacnha](https://github.com/sbc-khacnha) in [#&#8203;10081](celery/celery#10081)
- Make tests compatible with pymongo >= 4.16 by [@&#8203;cjwatson](https://github.com/cjwatson) in [#&#8203;10074](celery/celery#10074)
- fix: source install of cassandra-driver by [@&#8203;Izzette](https://github.com/Izzette) in [#&#8203;10105](celery/celery#10105)
- fix: register task cross-reference role in Sphinx extension by [@&#8203;veeceey](https://github.com/veeceey) in [#&#8203;10100](celery/celery#10100)
- fix: avoid cycle detection in native delayed delivery by [@&#8203;Izzette](https://github.com/Izzette) in [#&#8203;10095](celery/celery#10095)
- fix(asynpool): avoid AttributeError when proc lacks \_sentinel\_poll by [@&#8203;mriddle](https://github.com/mriddle) in [#&#8203;10086](celery/celery#10086)
- fix dusk\_astronomical horizon sign (+18 -> -18) by [@&#8203;Mr-Neutr0n](https://github.com/Mr-Neutr0n) in [#&#8203;10121](celery/celery#10121)
- Fix/10106 onupdate col use lambda func by [@&#8203;ChickenBenny](https://github.com/ChickenBenny) in [#&#8203;10108](celery/celery#10108)
- Fix warm shutdown RuntimeError with eventlet>=0.37.0 ([#&#8203;10083](celery/celery#10083)) by [@&#8203;ChickenBenny](https://github.com/ChickenBenny) in [#&#8203;10123](celery/celery#10123)
- Fix 10109 db backend connection health by [@&#8203;ChickenBenny](https://github.com/ChickenBenny) in [#&#8203;10124](celery/celery#10124)
- Database Backend filter unsupport sql engine arguments with nullpool [#&#8203;7355](celery/celery#7355) by [@&#8203;ChickenBenny](https://github.com/ChickenBenny) in [#&#8203;10134](celery/celery#10134)
- fix(beat): correct argument order in Service.**reduce** by [@&#8203;bysiber](https://github.com/bysiber) in [#&#8203;10137](celery/celery#10137)
- ci: declare explicit read-only token permissions in workflow jobs by [@&#8203;Rohan5commit](https://github.com/Rohan5commit) in [#&#8203;10139](celery/celery#10139)
- chore: 'boto3to' to 'boto3 to' by [@&#8203;cuiweixie](https://github.com/cuiweixie) in [#&#8203;10133](celery/celery#10133)
- Database Backend: Add missing index on date\_done (Fixes [#&#8203;10097](celery/celery#10097)) by [@&#8203;ChickenBenny](https://github.com/ChickenBenny) in [#&#8203;10098](celery/celery#10098)
- docs: fix typo in CONTRIBUTING.rst by [@&#8203;Rohan5commit](https://github.com/Rohan5commit) in [#&#8203;10141](celery/celery#10141)
- Refer to Flower / Prometheus for monitoring by [@&#8203;WilliamDEdwards](https://github.com/WilliamDEdwards) in [#&#8203;10140](celery/celery#10140)
- docs: remove duplicated words in broker and routing docs by [@&#8203;Rohan5commit](https://github.com/Rohan5commit) in [#&#8203;10146](celery/celery#10146)
- docs: fix stale version reference and grammar in README by [@&#8203;kelsonbrito50](https://github.com/kelsonbrito50) in [#&#8203;10145](celery/celery#10145)
- docs: fix wording in Celery 5.3 worker pool notes by [@&#8203;Rohan5commit](https://github.com/Rohan5commit) in [#&#8203;10149](celery/celery#10149)
- docs: fix duplicated wording in 3.1 changelog entry by [@&#8203;Rohan5commit](https://github.com/Rohan5commit) in [#&#8203;10152](celery/celery#10152)
- docs: fix changelog typo in context manager wording by [@&#8203;Rohan5commit](https://github.com/Rohan5commit) in [#&#8203;10144](celery/celery#10144)
- Fix/10096 worker fails to reconnect after redis failover by [@&#8203;ChickenBenny](https://github.com/ChickenBenny) in [#&#8203;10151](celery/celery#10151)
- Improve on\_after\_finalize signal documentation by [@&#8203;Br1an67](https://github.com/Br1an67) in [#&#8203;10155](celery/celery#10155)
- Add non-commutative example to clarify partial arg ordering in canvas docs by [@&#8203;Br1an67](https://github.com/Br1an67) in [#&#8203;10157](celery/celery#10157)
- Remove redundant test\_isa\_mapping test (fixes [#&#8203;10077](celery/celery#10077)) by [@&#8203;daniel7an](https://github.com/daniel7an) in [#&#8203;10103](celery/celery#10103)
- Upgrade pytest-celery to >=1.3.0 and adopt PYTEST\_CELERY\_PKG build arg by [@&#8203;Nusnus](https://github.com/Nusnus) in [#&#8203;10162](celery/celery#10162)
- Remove deprecated args from redis get\_connection call by [@&#8203;JaeHyuckSa](https://github.com/JaeHyuckSa) in [#&#8203;10036](celery/celery#10036)
- Fix [#&#8203;6912](celery/celery#6912) rpc backend reconnection error by [@&#8203;ChickenBenny](https://github.com/ChickenBenny) in [#&#8203;10179](celery/celery#10179)
- Fix NameError with TYPE\_CHECKING annotations on Python 3.14+ (PEP 649) by [@&#8203;drichardson](https://github.com/drichardson) in [#&#8203;10165](celery/celery#10165)
- docs: Add elaboration on prefetch multiplier settings (worker\_prefetch\_multiplier) and worker\_eta\_task\_limit by [@&#8203;tsangwailam](https://github.com/tsangwailam) in [#&#8203;10181](celery/celery#10181)
- Fix O(K²) message bloat in a chain of chords by [@&#8203;Borzik](https://github.com/Borzik) in [#&#8203;10171](celery/celery#10171)
- Fix mock connection interfaces to prevent `TypeError` during exception handling by [@&#8203;ChickenBenny](https://github.com/ChickenBenny) in [#&#8203;10178](celery/celery#10178)
- fix(trace): dispatch chain/callbacks on dedup fast-path for redelivered tasks by [@&#8203;aurangzaib048](https://github.com/aurangzaib048) in [#&#8203;10159](celery/celery#10159)
- Extract `reconnect_on_error` to `BaseResultConsumer` by [@&#8203;ChickenBenny](https://github.com/ChickenBenny) in [#&#8203;10189](celery/celery#10189)
- pep 649 by [@&#8203;ericbuehl](https://github.com/ericbuehl) in [#&#8203;10187](celery/celery#10187)
- [Fix#9722](https://github.com/Fix/celery/issues/9722) friendly status errors for CLI by [@&#8203;ChickenBenny](https://github.com/ChickenBenny) in [#&#8203;10190](celery/celery#10190)
- docs: clarify after\_return behavior for retried tasks by [@&#8203;KianAnbarestani](https://github.com/KianAnbarestani) in [#&#8203;10192](celery/celery#10192)
- Add compression header to message protocol docs by [@&#8203;Br1an67](https://github.com/Br1an67) in [#&#8203;10156](celery/celery#10156)
- docs: fix duplicated word in bootsteps comment by [@&#8203;Rohan5commit](https://github.com/Rohan5commit) in [#&#8203;10153](celery/celery#10153)
- Remove outdated autoreloader section from extending docs by [@&#8203;Br1an67](https://github.com/Br1an67) in [#&#8203;10154](celery/celery#10154)
- Fix: prioritize request ignore\_result over task definition by [@&#8203;patri27826](https://github.com/patri27826) in [#&#8203;10184](celery/celery#10184)
- fix: clear the timer while catch the exception by [@&#8203;ChickenBenny](https://github.com/ChickenBenny) in [#&#8203;10218](celery/celery#10218)
- Prepare for release: v5.6.3 by [@&#8203;Nusnus](https://github.com/Nusnus) in [#&#8203;10221](celery/celery#10221)

#### New Contributors

- [@&#8203;maycuatroi1](https://github.com/maycuatroi1) made their first contribution in [#&#8203;10048](celery/celery#10048)
- [@&#8203;jorsyk](https://github.com/jorsyk) made their first contribution in [#&#8203;10056](celery/celery#10056)
- [@&#8203;Timour-Ilyas](https://github.com/Timour-Ilyas) made their first contribution in [#&#8203;10066](celery/celery#10066)
- [@&#8203;sueannioanis](https://github.com/sueannioanis) made their first contribution in [#&#8203;10071](celery/celery#10071)
- [@&#8203;GangEunzzang](https://github.com/GangEunzzang) made their first contribution in [#&#8203;10076](celery/celery#10076)
- [@&#8203;sbc-khacnha](https://github.com/sbc-khacnha) made their first contribution in [#&#8203;10081](celery/celery#10081)
- [@&#8203;veeceey](https://github.com/veeceey) made their first contribution in [#&#8203;10100](celery/celery#10100)
- [@&#8203;mriddle](https://github.com/mriddle) made their first contribution in [#&#8203;10086](celery/celery#10086)
- [@&#8203;Mr-Neutr0n](https://github.com/Mr-Neutr0n) made their first contribution in [#&#8203;10121](celery/celery#10121)
- [@&#8203;ChickenBenny](https://github.com/ChickenBenny) made their first contribution in [#&#8203;10108](celery/celery#10108)
- [@&#8203;bysiber](https://github.com/bysiber) made their first contribution in [#&#8203;10137](celery/celery#10137)
- [@&#8203;Rohan5commit](https://github.com/Rohan5commit) made their first contribution in [#&#8203;10139](celery/celery#10139)
- [@&#8203;cuiweixie](https://github.com/cuiweixie) made their first contribution in [#&#8203;10133](celery/celery#10133)
- [@&#8203;kelsonbrito50](https://github.com/kelsonbrito50) made their first contribution in [#&#8203;10145](celery/celery#10145)
- [@&#8203;Br1an67](https://github.com/Br1an67) made their first contribution in [#&#8203;10155](celery/celery#10155)
- [@&#8203;daniel7an](https://github.com/daniel7an) made their first contribution in [#&#8203;10103](celery/celery#10103)
- [@&#8203;drichardson](https://github.com/drichardson) made their first contribution in [#&#8203;10165](celery/celery#10165)
- [@&#8203;tsangwailam](https://github.com/tsangwailam) made their first contribution in [#&#8203;10181](celery/celery#10181)
- [@&#8203;Borzik](https://github.com/Borzik) made their first contribution in [#&#8203;10171](celery/celery#10171)
- [@&#8203;aurangzaib048](https://github.com/aurangzaib048) made their first contribution in [#&#8203;10159](celery/celery#10159)
- [@&#8203;ericbuehl](https://github.com/ericbuehl) made their first contribution in [#&#8203;10187](celery/celery#10187)
- [@&#8203;KianAnbarestani](https://github.com/KianAnbarestani) made their first contribution in [#&#8203;10192](celery/celery#10192)
- [@&#8203;patri27826](https://github.com/patri27826) made their first contribution in [#&#8203;10184](celery/celery#10184)

**Full Changelog**: <celery/celery@v5.6.2...v5.6.3>

</details>

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My45OS4wIiwidXBkYXRlZEluVmVyIjoiNDMuOTkuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIiwicmVub3ZhdGUiXX0=-->

See merge request swiss-armed-forces/cyber-command/cea/loom!419
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.

3 participants