Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for MSSQL and psycopg3 error types #42

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading