diff options
| author | Julien Phalip <jphalip@gmail.com> | 2011-12-16 13:40:19 +0000 |
|---|---|---|
| committer | Julien Phalip <jphalip@gmail.com> | 2011-12-16 13:40:19 +0000 |
| commit | 34e248efeca272a2c0f2b15a5347dd66fc0340c9 (patch) | |
| tree | fd073f3b8a6132b002375ff454665bba090458fd /docs | |
| parent | 5df31c0164e9477a3ebb6b1bbde8604e06fbefd4 (diff) | |
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
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/1.4.txt | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/docs/releases/1.4.txt b/docs/releases/1.4.txt index 491556bfa2..f614dee5f8 100644 --- a/docs/releases/1.4.txt +++ b/docs/releases/1.4.txt @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
