The Fix
pip install celery==5.1.1
Based on closed celery/celery issue #6786 · PR/commit linked
Production note: This usually shows up under retries/timeouts. Treat it as a side-effect risk until you can verify behavior with a canary + real traffic.
@@ -241,12 +241,18 @@ def __bool__(self):
@property
def data(self):
- try:
- self.__consumed.extend(list(self.__it))
- except StopIteration:
In [1]: from celery.utils.functional import regen
In [2]: from collections import deque
In [3]: l = regen(deque([1]))
In [4]: l
Out[4]: [1]
In [5]: l
Out[5]: [1, 1]
In [6]: l
Out[6]: [1, 1, 1]
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\npip install celery==5.1.1\nWhen NOT to use: This fix is not applicable if the `regen()` behavior is intentionally lazy.\n\n
Why This Fix Works in Production
- Trigger: regen() duplicates any non-list and non-tuple sequence
- Mechanism: The `regen()` instances were not marked as done, leading to element duplication
- Why the fix works: Ensures that `regen()` instances are marked as done when concretised, preventing duplication of elements. (first fixed release: 5.1.1).
- If left unfixed, retries/timeouts can trigger duplicate external side-effects (double charges, duplicate emails, repeated writes).
Why This Breaks in Prod
- Triggered by an upgrade/regression window: 3.9.0 breaks; 5.1.1 is the first fixed release.
- The `regen()` instances were not marked as done, leading to element duplication
- Production symptom (often without a traceback): regen() duplicates any non-list and non-tuple sequence
Proof / Evidence
- GitHub issue: #6786
- Fix PR: https://github.com/celery/celery/pull/6789
- First fixed release: 5.1.1
- Affected versions: 3.9.0
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.73
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Quick bisect suggest this has been broken since 998277302 when regen was first rewritten to make it lazy”
“Hey @Suor :wave:, Thank you for opening an issue”
Failure Signature (Search String)
- regen() duplicates any non-list and non-tuple sequence
- - [x] I have included all related issues and possible duplicate issues
Copy-friendly signature
Failure Signature
-----------------
regen() duplicates any non-list and non-tuple sequence
- [x] I have included all related issues and possible duplicate issues
Error Message
Signature-only (no traceback captured)
Error Message
-------------
regen() duplicates any non-list and non-tuple sequence
- [x] I have included all related issues and possible duplicate issues
Minimal Reproduction
In [1]: from celery.utils.functional import regen
In [2]: from collections import deque
In [3]: l = regen(deque([1]))
In [4]: l
Out[4]: [1]
In [5]: l
Out[5]: [1, 1]
In [6]: l
Out[6]: [1, 1, 1]
What Broke
Elements were duplicated when accessing the `data` property of `regen()` instances.
Why It Broke
The `regen()` instances were not marked as done, leading to element duplication
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install celery==5.1.1
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/celery/celery/pull/6789
First fixed release: 5.1.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not applicable if the `regen()` behavior is intentionally lazy.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
- Pin production dependencies and upgrade only with a reproducible test that hits the failing path.
Version Compatibility Table
| Version | Status |
|---|---|
| 3.9.0 | Broken |
| 5.1.1 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.