--- id: django-dbconn-retry version: "0.3.1" license: unclear license_treatment: permissive maintenance: active --- # django-dbconn-retry — Patch Django to retry a database connection first before failing. License: permissive · Maintenance: active · Downloads: 92.1K/mo ## 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 above — 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 pip install django-dbconn-retry uv add django-dbconn-retry 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: unspecified - Install friction: low - Maintenance: active - Downloads: 92.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django database connection retry, django reconnect on connection closed, django tcp connection recovery, django database failover, django operational error handling, django connection pooling retry, django haproxy database connection, django vault credential refresh, django-integration, connection-resilience, haproxy-pgbouncer [View on SkillFed](https://skillfed.io/packages/django-dbconn-retry) · [View on PyPI](https://pypi.org/project/django-dbconn-retry/)