From cdbd31960e0cf41063b3efac97292ee0ccc262bb Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 9 Sep 2024 10:39:15 +0200 Subject: [PATCH] Refs #33817 -- Corrected errors raised when Oracle driver is not installed. oracledb_any should reraise ImportError instead of raising ImproperlyConfigured. --- django/db/backends/oracle/base.py | 6 +++++- django/db/backends/oracle/oracledb_any.py | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 5606f90653..df78d9ba27 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -14,13 +14,17 @@ from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.db import IntegrityError from django.db.backends.base.base import BaseDatabaseWrapper -from django.db.backends.oracle.oracledb_any import oracledb as Database from django.db.backends.utils import debug_transaction from django.utils.asyncio import async_unsafe from django.utils.encoding import force_bytes, force_str from django.utils.functional import cached_property from django.utils.version import get_version_tuple +try: + from django.db.backends.oracle.oracledb_any import oracledb as Database +except ImportError as e: + raise ImproperlyConfigured(f"Error loading oracledb module: {e}") + def _setup_environment(environ): # Cygwin requires some special voodoo to set the environment variables diff --git a/django/db/backends/oracle/oracledb_any.py b/django/db/backends/oracle/oracledb_any.py index 65d9f1d67d..22a9b78be8 100644 --- a/django/db/backends/oracle/oracledb_any.py +++ b/django/db/backends/oracle/oracledb_any.py @@ -1,6 +1,5 @@ import warnings -from django.core.exceptions import ImproperlyConfigured from django.utils.deprecation import RemovedInDjango60Warning try: @@ -18,4 +17,4 @@ except ImportError as e: ) is_oracledb = False except ImportError: - raise ImproperlyConfigured(f"Error loading oracledb module: {e}") + raise e from None