From 76990cbbda5d93fda560c8a5ab019860f7efaab7 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 14 Feb 2019 07:04:55 -0800 Subject: Fixed #30171 -- Fixed DatabaseError in servers tests. Made DatabaseWrapper thread sharing logic reentrant. Used a reference counting like scheme to allow nested uses. The error appeared after 8c775391b78b2a4a2b57c5e89ed4888f36aada4b. --- django/test/testcases.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'django/test') diff --git a/django/test/testcases.py b/django/test/testcases.py index 991165c04d..dea7fedbcc 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -1442,7 +1442,7 @@ class LiveServerTestCase(TransactionTestCase): # the server thread. if conn.vendor == 'sqlite' and conn.is_in_memory_db(): # Explicitly enable thread-shareability for this connection - conn.allow_thread_sharing = True + conn.inc_thread_sharing() connections_override[conn.alias] = conn cls._live_server_modified_settings = modify_settings( @@ -1478,10 +1478,9 @@ class LiveServerTestCase(TransactionTestCase): # Terminate the live server's thread cls.server_thread.terminate() - # Restore sqlite in-memory database connections' non-shareability - for conn in connections.all(): - if conn.vendor == 'sqlite' and conn.is_in_memory_db(): - conn.allow_thread_sharing = False + # Restore sqlite in-memory database connections' non-shareability. + for conn in cls.server_thread.connections_override.values(): + conn.dec_thread_sharing() @classmethod def tearDownClass(cls): -- cgit v1.3