Simplified django.db.utils.load_backend().

Previously load_backend() performed search by computing the (sole)
entry of django.db.backends.__path__ manually from
django.db.utils.__file__. Now django.db.backends.__path__ is used
directly.
This commit is contained in:
William Schwartz 2021-01-04 00:16:13 -06:00 committed by GitHub
parent 060e6bdd1f
commit 0ea1866f6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 3 deletions

View File

@ -1,6 +1,5 @@
import pkgutil
from importlib import import_module
from pathlib import Path
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
@ -113,9 +112,9 @@ def load_backend(backend_name):
except ImportError as e_user:
# The database backend wasn't found. Display a helpful error message
# listing all built-in database backends.
backend_dir = str(Path(__file__).parent / 'backends')
import django.db.backends
builtin_backends = [
name for _, name, ispkg in pkgutil.iter_modules([backend_dir])
name for _, name, ispkg in pkgutil.iter_modules(django.db.backends.__path__)
if ispkg and name not in {'base', 'dummy', 'postgresql_psycopg2'}
]
if backend_name not in ['django.db.backends.%s' % b for b in builtin_backends]: