mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #17258 -- Moved threading.local
from DatabaseWrapper
to the django.db.connections
dictionary. This allows connections to be explicitly shared between multiple threads and is particularly useful for enabling the sharing of in-memory SQLite connections. Many thanks to Anssi Kääriäinen for the excellent suggestions and feedback, and to Alex Gaynor for the reviews. Refs #2879.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17205 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5df31c0164
commit
34e248efec
6 changed files with 187 additions and 11 deletions
|
@ -673,6 +673,32 @@ datetimes are now stored without time zone information in SQLite. When
|
|||
:setting:`USE_TZ` is ``False``, if you attempt to save an aware datetime
|
||||
object, Django raises an exception.
|
||||
|
||||
Database connection's thread-locality
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
``DatabaseWrapper`` objects (i.e. the connection objects referenced by
|
||||
``django.db.connection`` and ``django.db.connections["some_alias"]``) used to
|
||||
be thread-local. They are now global objects in order to be potentially shared
|
||||
between multiple threads. While the individual connection objects are now
|
||||
global, the ``django.db.connections`` dictionary referencing those objects is
|
||||
still thread-local. Therefore if you just use the ORM or
|
||||
``DatabaseWrapper.cursor()`` then the behavior is still the same as before.
|
||||
Note, however, that ``django.db.connection`` does not directly reference the
|
||||
default ``DatabaseWrapper`` object any more and is now a proxy to access that
|
||||
object's attributes. If you need to access the actual ``DatabaseWrapper``
|
||||
object, use ``django.db.connections[DEFAULT_DB_ALIAS]`` instead.
|
||||
|
||||
As part of this change, all underlying SQLite connections are now enabled for
|
||||
potential thread-sharing (by passing the ``check_same_thread=False`` attribute
|
||||
to pysqlite). ``DatabaseWrapper`` however preserves the previous behavior by
|
||||
disabling thread-sharing by default, so this does not affect any existing
|
||||
code that purely relies on the ORM or on ``DatabaseWrapper.cursor()``.
|
||||
|
||||
Finally, while it is now possible to pass connections between threads, Django
|
||||
does not make any effort to synchronize access to the underlying backend.
|
||||
Concurrency behavior is defined by the underlying backend implementation.
|
||||
Check their documentation for details.
|
||||
|
||||
`COMMENTS_BANNED_USERS_GROUP` setting
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue