Jump to solution
Verify

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%.

Jump to Verify Open PR/Commit
@@ -16,6 +16,7 @@ from typing import Protocol + from django.db.backends.base.base import BaseDatabaseWrapper from django.db.utils import ConnectionHandler
repro.py
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
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
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).
Production impact:
  • 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”
@auvipy · 2024-09-24 · source
“thanks for the report. would you mind contributing a fix?”
@auvipy · 2024-09-24 · source
“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…”
@orf · 2024-09-27 · source
“We got a fix for this, can you please check it out?”
@auvipy · 2024-12-25 · source

Failure Signature (Search String)

  • In [1]: import django.db

Error Message

Stack trace
error.txt
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

repro.py
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

When NOT to use: This fix is not suitable if you need to handle specific exceptions differently.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not suitable if you need to handle specific exceptions differently.

Verify Fix

verify
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

VersionStatus
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.