Repository navigation
Fix autoretry retry kwargs mutation - #10458
daleselaji-dev wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Celery’s autoretry_for wrapper mutating a single shared retry_kwargs dict captured at task registration time, which could corrupt computed backoff values across executions (including concurrent executions in a worker process).
Changes:
- Copy
retry_kwargsper retry attempt before adding/overridingcountdownandmax_retries, avoiding cross-execution mutation. - Add a regression unit test ensuring the caller-provided
retry_kwargsdict remains unchanged while backoff countdowns are still computed correctly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
celery/app/autoretry.py |
Avoids mutating the shared retry_kwargs by copying it per retry attempt before adding calculated values. |
t/unit/tasks/test_tasks.py |
Adds a regression test asserting retry_kwargs is not mutated and that backoff countdowns match expectations. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10458 +/- ##
=======================================
Coverage 88.44% 88.44%
=======================================
Files 153 153
Lines 19808 19809 +1
Branches 2304 2304
=======================================
+ Hits 17519 17520 +1
Misses 1993 1993
Partials 296 296
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
|
Nice fix, verified it works. One code path this doesn't have test coverage for: @aviadatsnyk if you agree this is worth covering, happy to implement the regression test — as I mentioned in the issue, I was already working on this. |
Description
Fixes #10456.
The autoretry wrapper now copies retry_kwargs for each retry attempt before adding calculated countdown or max_retries values. This prevents the task-level dictionary captured by the wrapper from being mutated and shared between executions.
Added a regression test covering retry backoff values and verifying that the caller-provided dictionary remains unchanged.
Verification