Socket
Socket
Sign inDemoInstall

django-db-connection-retrier

Package Overview
Dependencies
2
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    django-db-connection-retrier

Automatically ty re-establishing the Django database connection when it gets lost.


Maintainers
1

Readme

Django Database Connection Retrier

License PyPi CircleCI

Automatically try to re-establish Django database connections when they fail due to DNS errors.


When the Django app (dbconnectionretrier) loads, a hook is installed in Django's BaseDatabaseWrapper.ensure_connection that catches django.db.OperationalError. If the error raised is a DNS error, the connction attempt is retried synchronously three times.


Tested on Django 2.0-2.3 and Python 3.7 and 3.8. Might work with other versions of Django and Python.

Installation

  1. Install the package from PyPi:

     $ pip install django-db-connection-retrier
    
  2. Add dbconnectionretrier to your INSTALLED_APPS:

     INSTALLED_APPS = [
         'dbconnectionretrier',
         ...
     ]
    

Manual usage

Adding dbconnectionretrier to INSTALLED_APPS enables automatic connection retrying. Want more granular control over patching?

Globally

from dbconnectionretrier.patch import patch_ensure_connection

# after this line executes, connection retrying is enabled
patch = patch_ensure_connection()

# after this line, the connection retrying is disabled
patch.rollback()

Context manager

from dbconnectionretrier.patch import patch_ensure_connection_contextual

with patch_ensure_connection_contextual():
    # all code inside this block benefits from connection retrying

Keywords

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc