summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3
diff options
context:
space:
mode:
authorJulien Phalip <jphalip@gmail.com>2011-12-16 13:40:19 +0000
committerJulien Phalip <jphalip@gmail.com>2011-12-16 13:40:19 +0000
commit34e248efeca272a2c0f2b15a5347dd66fc0340c9 (patch)
treefd073f3b8a6132b002375ff454665bba090458fd /django/db/backends/sqlite3
parent5df31c0164e9477a3ebb6b1bbde8604e06fbefd4 (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 'django/db/backends/sqlite3')
-rw-r--r--django/db/backends/sqlite3/base.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index a610606635..75e8fa027d 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -7,10 +7,10 @@ standard library.
import datetime
import decimal
+import warnings
import re
import sys
-from django.conf import settings
from django.db import utils
from django.db.backends import *
from django.db.backends.signals import connection_created
@@ -241,6 +241,21 @@ class DatabaseWrapper(BaseDatabaseWrapper):
'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
}
kwargs.update(settings_dict['OPTIONS'])
+ # Always allow the underlying SQLite connection to be shareable
+ # between multiple threads. The safe-guarding will be handled at a
+ # higher level by the `BaseDatabaseWrapper.allow_thread_sharing`
+ # property. This is necessary as the shareability is disabled by
+ # default in pysqlite and it cannot be changed once a connection is
+ # opened.
+ if 'check_same_thread' in kwargs and kwargs['check_same_thread']:
+ warnings.warn(
+ 'The `check_same_thread` option was provided and set to '
+ 'True. It will be overriden with False. Use the '
+ '`DatabaseWrapper.allow_thread_sharing` property instead '
+ 'for controlling thread shareability.',
+ RuntimeWarning
+ )
+ kwargs.update({'check_same_thread': False})
self.connection = Database.connect(**kwargs)
# Register extract, date_trunc, and regexp functions.
self.connection.create_function("django_extract", 2, _sqlite_extract)