{"id":25044958,"url":"https://github.com/sectorlabs/django-db-connection-retrier","last_synced_at":"2025-04-14T02:01:45.414Z","repository":{"id":54544129,"uuid":"208879560","full_name":"SectorLabs/django-db-connection-retrier","owner":"SectorLabs","description":"Automatically re-establish Django's database connection when it fails due to DNS errors.","archived":false,"fork":false,"pushed_at":"2024-03-20T15:46:30.000Z","size":15,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-27T15:56:02.765Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SectorLabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-09-16T19:20:47.000Z","updated_at":"2024-10-23T14:08:49.000Z","dependencies_parsed_at":"2025-04-14T02:00:57.785Z","dependency_job_id":null,"html_url":"https://github.com/SectorLabs/django-db-connection-retrier","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SectorLabs%2Fdjango-db-connection-retrier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SectorLabs%2Fdjango-db-connection-retrier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SectorLabs%2Fdjango-db-connection-retrier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SectorLabs%2Fdjango-db-connection-retrier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SectorLabs","download_url":"https://codeload.github.com/SectorLabs/django-db-connection-retrier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248809032,"owners_count":21164895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-06T05:20:01.218Z","updated_at":"2025-04-14T02:01:45.360Z","avatar_url":"https://github.com/SectorLabs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django Database Connection Retrier\n\n[![License](https://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)\n[![PyPi](https://badge.fury.io/py/django-db-connection-retrier.svg)](https://pypi.python.org/pypi/django-db-connection-retrier)\n[![CircleCI](https://circleci.com/gh/SectorLabs/django-db-connection-retrier/tree/master.svg?style=svg\u0026circle-token=8177e64d426308c93d38af49a1cca1df4225bc67)](https://circleci.com/gh/SectorLabs/django-db-connection-retrier/tree/master)\n\nAutomatically try to re-establish Django database connections when they fail due to DNS errors.\n\n---\n\nWhen the Django app (`dbconnectionretrier`) loads, a hook is installed in Django's [`BaseDatabaseWrapper.ensure_connection`](https://github.com/django/django/blob/master/django/db/backends/base/base.py#L216) that catches `django.db.OperationalError`. If the error raised is a DNS error, the connction attempt is retried synchronously **three times**.\n\n---\n\nTested on Django 2.0-2.3 and Python 3.7 and 3.8. Might work with other versions of Django and Python.\n\n## Installation\n1. Install the package from PyPi:\n\n        $ pip install django-db-connection-retrier\n\n2. Add `dbconnectionretrier` to your `INSTALLED_APPS`:\n\n        INSTALLED_APPS = [\n            'dbconnectionretrier',\n            ...\n        ]\n\n## Manual usage\nAdding `dbconnectionretrier` to `INSTALLED_APPS` enables automatic connection retrying. Want more granular control over patching?\n\n### Globally\n```\nfrom dbconnectionretrier.patch import patch_ensure_connection\n\n# after this line executes, connection retrying is enabled\npatch = patch_ensure_connection()\n\n# after this line, the connection retrying is disabled\npatch.rollback()\n```\n\n### Context manager\n```\nfrom dbconnectionretrier.patch import patch_ensure_connection_contextual\n\nwith patch_ensure_connection_contextual():\n    # all code inside this block benefits from connection retrying\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsectorlabs%2Fdjango-db-connection-retrier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsectorlabs%2Fdjango-db-connection-retrier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsectorlabs%2Fdjango-db-connection-retrier/lists"}