From 10b490a8a1d34c173e3082665b226d78e8b732e8 Mon Sep 17 00:00:00 2001 From: vbaskeran Date: Wed, 14 Feb 2024 10:33:39 +0800 Subject: [PATCH 1/3] feat: Add support for MSSQL and psycopg3 error types --- django_dbconn_retry/apps.py | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/django_dbconn_retry/apps.py b/django_dbconn_retry/apps.py index 04f9dad..37bb519 100644 --- a/django_dbconn_retry/apps.py +++ b/django_dbconn_retry/apps.py @@ -15,27 +15,22 @@ post_reconnect = Signal() _operror_types = () # type: Union[Tuple[type], Tuple] -_operror_types += (django_db_utils.OperationalError,) -try: - import psycopg2 -except ImportError: - pass -else: - _operror_types += (psycopg2.OperationalError,) - -try: - import sqlite3 -except ImportError: - pass -else: - _operror_types += (sqlite3.OperationalError,) - -try: - import MySQLdb -except ImportError: - pass -else: - _operror_types += (MySQLdb.OperationalError,) +database_modules = [ + ("django_db_utils", "OperationalError"), + ("psycopg2", "OperationalError"), + ("psycopg", "OperationalError"), + ("sqlite3", "OperationalError"), + ("MySQLdb", "OperationalError"), + ("pyodbc", "InterfaceError"), +] + +for module_name, error_name in database_modules: + try: + module = __import__(module_name, fromlist=[error_name]) + error_type = getattr(module, error_name) + _operror_types += (error_type,) + except ImportError: + pass def monkeypatch_django() -> None: From 0a65eccacc4394d1758e826c8e8351b83de99d72 Mon Sep 17 00:00:00 2001 From: Jonas Maurus Date: Thu, 11 Apr 2024 14:06:11 +0200 Subject: [PATCH 2/3] empty commit to trigger tests From 40dd61da178eefd4fb23806afb0f5871a2121e5e Mon Sep 17 00:00:00 2001 From: Jonas Maurus Date: Thu, 11 Apr 2024 14:34:31 +0200 Subject: [PATCH 3/3] fix reference to django.db.utils --- django_dbconn_retry/apps.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/django_dbconn_retry/apps.py b/django_dbconn_retry/apps.py index 37bb519..d509cce 100644 --- a/django_dbconn_retry/apps.py +++ b/django_dbconn_retry/apps.py @@ -1,7 +1,6 @@ import logging from django.apps.config import AppConfig -from django.db import utils as django_db_utils from django.db.backends.base import base as django_db_base from django.dispatch import Signal @@ -16,7 +15,7 @@ _operror_types = () # type: Union[Tuple[type], Tuple] database_modules = [ - ("django_db_utils", "OperationalError"), + ("django.db.utils", "OperationalError"), ("psycopg2", "OperationalError"), ("psycopg", "OperationalError"), ("sqlite3", "OperationalError"),