The Fix
pip install celery==5.5.0
Based on closed celery/celery issue #9310 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -16,6 +16,7 @@
from typing import Protocol
+ from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.utils import ConnectionHandler
In [1]: import django.db
In [2]: connection = django.db.connections.all()[0]
In [3]: connection.connection
Out[3]: <psycopg.Connection [IDLE] (host=localhost database=postgres) at 0x1332340b0>
In [4]: connection.connection.fileno()
Out[4]: 13
In [5]: connection.connection.close()
In [6]: connection.connection.fileno()
...
psycopg.OperationalError: the connection is closed
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.5.0\nWhen NOT to use: This fix is not suitable if you need to handle specific exceptions differently.\n\n
Why This Fix Works in Production
- Trigger: In [1]: import django.db
- Mechanism: Celery fails to catch psycopg2 specific exceptions when closing database connections
- Why the fix works: Fixes the issue by catching the correct database errors when attempting to close a database connection in Django. (first fixed release: 5.5.0).
- 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
- Celery fails to catch psycopg2 specific exceptions when closing database connections
- Surfaces as: In [1]: import django.db
Proof / Evidence
- GitHub issue: #9310
- Fix PR: https://github.com/celery/celery/pull/9392
- First fixed release: 5.5.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.56
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“No problem, lets start with a draft POC? then we will see”
“thanks for the report. would you mind contributing a fix?”
“Hey, I’m on holiday for two weeks and so won’t be able to tackle this. I’ve added it to my queue and I’ll take a…”
“We got a fix for this, can you please check it out?”
Failure Signature (Search String)
- In [1]: import django.db
Error Message
Stack trace
Error Message
-------------
In [1]: import django.db
In [2]: connection = django.db.connections.all()[0]
In [3]: connection.connection
Out[3]: <psycopg.Connection [IDLE] (host=localhost database=postgres) at 0x1332340b0>
In [4]: connection.connection.fileno()
Out[4]: 13
In [5]: connection.connection.close()
In [6]: connection.connection.fileno()
...
psycopg.OperationalError: the connection is closed
Minimal Reproduction
In [1]: import django.db
In [2]: connection = django.db.connections.all()[0]
In [3]: connection.connection
Out[3]: <psycopg.Connection [IDLE] (host=localhost database=postgres) at 0x1332340b0>
In [4]: connection.connection.fileno()
Out[4]: 13
In [5]: connection.connection.close()
In [6]: connection.connection.fileno()
...
psycopg.OperationalError: the connection is closed
What Broke
Attempting to close an already closed database connection results in an InterfaceError.
Why It Broke
Celery fails to catch psycopg2 specific exceptions when closing database connections
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install celery==5.5.0
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/9392
First fixed release: 5.5.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not suitable if you need to handle specific exceptions differently.
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 |
|---|---|
| 5.5.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.