django-dbconn-retry
raw JSON → 0.2.0 verified Fri May 01 auth: no python
Patches Django's database connection handling to automatically retry failed connections before raising an error. Useful for environments with brief database unavailability (e.g., container restarts, network blips). Current version 0.2.0, maintained sporadically.
pip install django-dbconn-retry Common errors
error ImportError: No module named django_dbconn_retry ↓
cause Using hyphens or underscores in the package name for import; the correct import is 'djangodbconnretry'.
fix
Use 'from djangodbconnretry import patch_conn'
error AttributeError: module 'django.db.backends.base.base' has no attribute 'get_new_connection' ↓
cause The package monkey-patches an internal Django method that may have changed or been removed in newer Django versions.
fix
Check Django version compatibility. For Django >= 2.1, consider writing your own database backend wrapper or using a modern alternative.
Warnings
gotcha The package only retries connection-time errors, not query-time errors (e.g., deadlocks). It wraps the database wrapper's get_new_connection method, so transient query failures are NOT retried. ↓
fix Understand the scope: only initial connection failures are retried. For query retries, consider other tools like django-tenacity.
gotcha patch_conn() must be called after django.setup() but before any database access. If called too early (before settings are loaded) or too late (after connections already attempted), it may not work as expected. ↓
fix Ensure django.setup() is called before patch_conn() in your manage.py or wsgi.py setup.
deprecated The package appears unmaintained (last release 2018). It may not work with Django 2.1+ without modifications due to changes in database backends. ↓
fix Test with your Django version; consider alternatives like custom database backends or django-retry-if-fails.
Imports
- patch_conn wrong
from django_dbconn_retry import patch_conncorrectfrom djangodbconnretry import patch_conn
Quickstart
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
import django
django.setup()
from djangodbconnretry import patch_conn
patch_conn()
# Now all DB connections will retry on failure