Skip to main content

A Django middleware and decorator to automatically handle database connection losses.

Project description

Django DB Reconnect

A simple Django app that provides a middleware and a decorator to automatically handle database connection losses (e.g., "MySQL server has gone away").

This utility catches specific OperationalError exceptions, closes the stale database connections, and retries the operation once. This can help improve the stability of long-running Django applications or applications with intermittent network access to the database.

Installation

pip install bear-django-query-profiler

Usage

  1. Add the middleware to your MIDDLEWARE list in settings.py.
# settings.py
MIDDLEWARE = [
    'db_reconnect.middleware.DBConnectionMiddleware',
]
  1. (Optional) You can override this list by defining DB_RECONNECT_ERROR_CODES in your settings.py.
# settings.py
DB_RECONNECT_ERROR_CODES = [2006, 2013]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bear_django_db_reconnect-0.1.0.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bear_django_db_reconnect-0.1.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file bear_django_db_reconnect-0.1.0.tar.gz.

File metadata

File hashes

Hashes for bear_django_db_reconnect-0.1.0.tar.gz
Algorithm Hash digest
SHA256 730be896061ec98756349bd5f03a3b72d3b90d72d63cbdb1594a4703067e30b7
MD5 7c6b7baa7f1c3c550db2d1d75714b412
BLAKE2b-256 6b80e8c46edecf243bf140265986a9d6e25de4445170b0abdd0a0644d4720650

See more details on using hashes here.

File details

Details for the file bear_django_db_reconnect-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bear_django_db_reconnect-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7a2549a90e2fc3e80a6a01fd876931eae02d99771097313b15870e641eee04f
MD5 e25890487b11c4c403c2b08bc7e62154
BLAKE2b-256 2f2349222533d59268d5bf08d974b83483a9cefacafa082d0bc0f3e1da25fdb9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page