The Fix
pip install celery==5.1.1
Based on closed celery/celery issue #6781 · 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.
@@ -75,6 +75,7 @@ def connection(self):
def get(self, key):
+ key = bytes_to_str(key)
try:
return self.connection.get(key)['value']
from celery import Celery
app = Celery("tasks", broker="pyamqp://....", backend="couchdb://...")
@app.task
def add(x, y):
return x + y
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 should not be applied if the key is expected to remain a bytes-like object.\n\n
Why This Fix Works in Production
- Trigger: [2021-05-23 19:34:24,965: ERROR/MainProcess] Pool callback raised exception: TypeError("a bytes-like object is required, not 'str'")
- Mechanism: The couchdb backend's get() method was not converting the key to a string, causing a TypeError
- Why the fix works: Fixes the couchdb backend call get() method by converting the key to a string, addressing the TypeError encountered in issue #6781. (first fixed release: 5.1.1).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Triggered by an upgrade/regression window: 1.6.5 breaks; 5.1.1 is the first fixed release.
- Shows up under Python 3.9 in real deployments (not just unit tests).
- The couchdb backend's get() method was not converting the key to a string, causing a TypeError
- Surfaces as: [2021-05-23 19:34:24,965: ERROR/MainProcess] Pool callback raised exception: TypeError("a bytes-like object is required, not 'str'")
Proof / Evidence
- GitHub issue: #6781
- Fix PR: https://github.com/celery/celery/pull/6782
- First fixed release: 5.1.1
- Affected versions: 1.6.5
- 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.44
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Hey @worldworm :wave:, Thank you for opening an issue”
“I tried my hand at a fix once. For other backends, it seems that the key is also converted to a string.”
Failure Signature (Search String)
- [2021-05-23 19:34:24,965: ERROR/MainProcess] Pool callback raised exception: TypeError("a bytes-like object is required, not 'str'")
Error Message
Stack trace
Error Message
-------------
[2021-05-23 19:34:24,965: ERROR/MainProcess] Pool callback raised exception: TypeError("a bytes-like object is required, not 'str'")
Traceback (most recent call last):
File "/config/.local/lib/python3.9/site-packages/billiard/pool.py", line 1796, in safe_apply_callback
fun(*args, **kwargs)
File "/config/.local/lib/python3.9/site-packages/celery/worker/request.py", line 567, in on_failure
self.task.backend.mark_as_failure(
File "/config/.local/lib/python3.9/site-packages/celery/backends/base.py", line 171, in mark_as_failure
self.store_result(task_id, exc, state,
File "/config/.local/lib/python3.9/site-packages/celery/backends/base.py", line 477, in store_result
self._store_result(task_id, result, state, traceback,
File "/config/.local/lib/python3.9/site-packages/celery/backends/base.py", line 898, in _store_result
current_meta = self._get_task_meta_for(task_id)
File "/config/.local/lib/python3.9/site-packages/celery/backends/base.py", line 920, in _get_task_meta_for
meta = self.get(self.get_key_for_task(task_id))
File "/config/.local/lib/python3.9/site-packages/celery/backends/couchdb.py", line 79, in get
return self.connection.get(key)['value']
File "/config/.local/lib/python3.9/site-packages/pycouchdb/client.py", line 345, in get
(resp, result) = self.resource(*_id_to_path(doc_id)).get(params=params)
File "/config/.local/lib/p
... (truncated) ...
Minimal Reproduction
from celery import Celery
app = Celery("tasks", broker="pyamqp://....", backend="couchdb://...")
@app.task
def add(x, y):
return x + y
Environment
- Python: 3.9
What Broke
CouchDB backend calls resulted in TypeErrors, preventing successful data retrieval.
Why It Broke
The couchdb backend's get() method was not converting the key to a string, causing a TypeError
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/6782
First fixed release: 5.1.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if the key is expected to remain a bytes-like object.
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 |
|---|---|
| 1.6.5 | 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.