class ConnectionHandler
from django.db.utils import ConnectionHandler
Ancestors (MRO)
- builtins.object
- django.utils.connection.BaseConnectionHandler
- django.db.utils.ConnectionHandler
Attribute | Value | Defined in |
---|---|---|
exception_class |
<class 'django.utils.connection.ConnectionDoesNotExist'> |
django.utils.connection.BaseConnectionHandler |
settings_name |
DATABASES |
django.db.utils.ConnectionHandler |
settings_name |
None |
django.utils.connection.BaseConnectionHandler |
thread_critical |
True |
django.db.utils.ConnectionHandler |
thread_critical |
False |
django.utils.connection.BaseConnectionHandler |
def all(self, initialized_only=False)
django.utils.connection.BaseConnectionHandler
def all(self, initialized_only=False):
return [
self[alias]
for alias in self
# If initialized_only is True, return only initialized connections.
if not initialized_only or hasattr(self._connections, alias)
]
def close_all(self)
django.utils.connection.BaseConnectionHandler
def close_all(self):
for conn in self.all(initialized_only=True):
conn.close()
def configure_settings(self, databases)
django.db.utils.ConnectionHandler
django.db.utils.ConnectionHandler
def configure_settings(self, databases):
databases = super().configure_settings(databases)
if databases == {}:
databases[DEFAULT_DB_ALIAS] = {"ENGINE": "django.db.backends.dummy"}
elif DEFAULT_DB_ALIAS not in databases:
raise ImproperlyConfigured(
f"You must define a '{DEFAULT_DB_ALIAS}' database."
)
elif databases[DEFAULT_DB_ALIAS] == {}:
databases[DEFAULT_DB_ALIAS]["ENGINE"] = "django.db.backends.dummy"
# Configure default settings.
for conn in databases.values():
conn.setdefault("ATOMIC_REQUESTS", False)
conn.setdefault("AUTOCOMMIT", True)
conn.setdefault("ENGINE", "django.db.backends.dummy")
if conn["ENGINE"] == "django.db.backends." or not conn["ENGINE"]:
conn["ENGINE"] = "django.db.backends.dummy"
conn.setdefault("CONN_MAX_AGE", 0)
conn.setdefault("CONN_HEALTH_CHECKS", False)
conn.setdefault("OPTIONS", {})
conn.setdefault("TIME_ZONE", None)
for setting in ["NAME", "USER", "PASSWORD", "HOST", "PORT"]:
conn.setdefault(setting, "")
test_settings = conn.setdefault("TEST", {})
default_test_settings = [
("CHARSET", None),
("COLLATION", None),
("MIGRATE", True),
("MIRROR", None),
("NAME", None),
]
for key, value in default_test_settings:
test_settings.setdefault(key, value)
return databases
django.utils.connection.BaseConnectionHandler
def configure_settings(self, settings):
if settings is None:
settings = getattr(django_settings, self.settings_name)
return settings
def create_connection(self, alias)
django.db.utils.ConnectionHandler
django.db.utils.ConnectionHandler
def create_connection(self, alias):
db = self.settings[alias]
backend = load_backend(db["ENGINE"])
return backend.DatabaseWrapper(db, alias)
django.utils.connection.BaseConnectionHandler
def create_connection(self, alias):
raise NotImplementedError("Subclasses must implement create_connection().")
def databases(self)
django.db.utils.ConnectionHandler
def settings(self)
django.utils.connection.BaseConnectionHandler