mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
A large number of stylistic cleanups across django/db/
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
import warnings
|
||||
|
||||
from django.core import signals
|
||||
from django.db.utils import (DEFAULT_DB_ALIAS,
|
||||
DataError, OperationalError, IntegrityError, InternalError,
|
||||
ProgrammingError, NotSupportedError, DatabaseError,
|
||||
InterfaceError, Error,
|
||||
load_backend, ConnectionHandler, ConnectionRouter)
|
||||
from django.db.utils import (DEFAULT_DB_ALIAS, DataError, OperationalError,
|
||||
IntegrityError, InternalError, ProgrammingError, NotSupportedError,
|
||||
DatabaseError, InterfaceError, Error, load_backend,
|
||||
ConnectionHandler, ConnectionRouter)
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
__all__ = ('backend', 'connection', 'connections', 'router', 'DatabaseError',
|
||||
'IntegrityError', 'DEFAULT_DB_ALIAS')
|
||||
|
||||
__all__ = [
|
||||
'backend', 'connection', 'connections', 'router', 'DatabaseError',
|
||||
'IntegrityError', 'InternalError', 'ProgrammingError', 'DataError',
|
||||
'NotSupportedError', 'Error', 'InterfaceError', 'OperationalError',
|
||||
'DEFAULT_DB_ALIAS'
|
||||
]
|
||||
|
||||
connections = ConnectionHandler()
|
||||
|
||||
router = ConnectionRouter()
|
||||
|
||||
|
||||
# `connection`, `DatabaseError` and `IntegrityError` are convenient aliases
|
||||
# for backend bits.
|
||||
|
||||
@@ -70,6 +75,7 @@ class DefaultBackendProxy(object):
|
||||
|
||||
backend = DefaultBackendProxy()
|
||||
|
||||
|
||||
def close_connection(**kwargs):
|
||||
warnings.warn(
|
||||
"close_connection is superseded by close_old_connections.",
|
||||
@@ -83,12 +89,14 @@ def close_connection(**kwargs):
|
||||
transaction.abort(conn)
|
||||
connections[conn].close()
|
||||
|
||||
|
||||
# Register an event to reset saved queries when a Django request is started.
|
||||
def reset_queries(**kwargs):
|
||||
for conn in connections.all():
|
||||
conn.queries = []
|
||||
signals.request_started.connect(reset_queries)
|
||||
|
||||
|
||||
# Register an event to reset transaction state and close connections past
|
||||
# their lifetime. NB: abort() doesn't do anything outside of a transaction.
|
||||
def close_old_connections(**kwargs):
|
||||
|
||||
Reference in New Issue
Block a user