skillfed

django-dbconn-retry

Patch Django to retry a database connection first before failing.

django-dbconn-retry v0.3.1 92.1K downloads/30d#13,474 on PyPI83
Permissive license Active released

What it is and what it does

django-dbconn-retry patches Django's database wrapper to handle closed TCP connections gracefully. When a database operation fails because the connection was already closed—a common issue when using load balancers like HAProxy or connection poolers like pgbouncer—the library automatically attempts to reconnect and retry the operation instead of immediately raising an OperationalError.

The package is configured via Django settings (MAX_DBCONN_RETRY_TIMES, DBCONN_RETRY_DELAY, DBCONN_RETRY_BACKOFF) and exposes Django Signals (pre_reconnect, post_reconnect) to allow other code to hook into the reconnection process. This is useful for scenarios like refreshing database credentials from Hashicorp Vault before reconnecting, or handling credential expiration in dynamic authentication systems.

Use it for:

  • Recover from transient connection drops caused by HAProxy or pgbouncer load balancers without raising exceptions to the application.
  • Automatically refresh database credentials from Hashicorp Vault when a connection fails due to expired credentials.
  • Reduce application crashes and improve resilience in environments with aggressive connection timeout policies.
  • Implement graceful retry logic for database operations in microservices architectures with unstable network conditions.
  • Handle connection state mismatches in high-availability database setups without explicit application-level retry code.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Automatically reconnects Django database connections when the underlying TCP connection has been closed, retrying the failed operation instead of immediately raising an OperationalError.

Yes, if you run Django with load-balanced or pooled database connections (HAProxy, pgbouncer, Vault). The package solves a real operational problem with low friction and no dependencies. No known vulnerabilities. Active maintenance and permissive license. Not necessary if your database connections are stable and direct.

Install

django-dbconn-retry on PyPI

pip

pip install django-dbconn-retry

uv

uv add django-dbconn-retry

poetry

poetry add django-dbconn-retry

Installing django-dbconn-retry

Before you install

Low install friction with no runtime dependencies. Active maintenance as of 2026-05-02, with recent repository activity (last commit 2026-08-10). Moderate popularity at top_15000 tier with ~92140 monthly downloads.

License in practice

BSD License (permissive). Allows commercial use, modification, and distribution with minimal restrictions—only requires retaining copyright notice and disclaimer.

Quickstart

pip install django-dbconn-retry

# In settings.py, add to INSTALLED_APPS:
INSTALLED_APPS = [
    'django_dbconn_retry',
    # ...
]

# Optional: configure retry behavior
MAX_DBCONN_RETRY_TIMES = 1  # default
DBCONN_RETRY_DELAY = 0  # default
DBCONN_RETRY_BACKOFF = 1  # default

Verify before relying

  • Whether the package works with all Django versions or has specific version constraints not listed in the fact sheet.
  • Whether the monkeypatch approach has any known incompatibilities with other Django middleware or database backends.
  • Performance impact of the retry mechanism under high-concurrency workloads.

Package facts

License not declared (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 104 days since the last release
Last repo commit
First released
Downloads 92,140/month — #13,474 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: django_dbconn_retry-0.3.1-py3-none-any.whl

Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: System AdministratorsLicense :: OSI Approved :: BSD LicenseOperating System :: POSIXProgramming Language :: Python :: 3 :: Only

Tags

django database connection retrydjango reconnect on connection closeddjango tcp connection recoverydjango database failoverdjango operational error handlingdjango connection pooling retrydjango haproxy database connectiondjango vault credential refresh
django-integrationconnection-resiliencehaproxy-pgbouncer

More Database packages