Skip to content

Commit

Permalink
Merge pull request #42 from vecknishwaran/mssql-psycopg3-support
Browse files Browse the repository at this point in the history
feat: Add support for MSSQL and psycopg3 error types
  • Loading branch information
jdelic authored Apr 11, 2024
2 parents c49e664 + 40dd61d commit 7ba76f5
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions django_dbconn_retry/apps.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -15,27 +14,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:
Expand Down

0 comments on commit 7ba76f5

Please sign in to comment.