mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Changed database connection duplication technique.
This new technique is more straightforward and compatible with test parallelization, where the effective database connection settings no longer match settings.DATABASES.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import copy
|
||||
import time
|
||||
import warnings
|
||||
from collections import deque
|
||||
@@ -622,3 +623,16 @@ class BaseDatabaseWrapper(object):
|
||||
func()
|
||||
finally:
|
||||
self.run_on_commit = []
|
||||
|
||||
def copy(self, alias=None, allow_thread_sharing=None):
|
||||
"""
|
||||
Return a copy of this connection.
|
||||
|
||||
For tests that require two connections to the same database.
|
||||
"""
|
||||
settings_dict = copy.deepcopy(self.settings_dict)
|
||||
if alias is None:
|
||||
alias = self.alias
|
||||
if allow_thread_sharing is None:
|
||||
allow_thread_sharing = self.allow_thread_sharing
|
||||
return type(self)(settings_dict, alias, allow_thread_sharing)
|
||||
|
||||
Reference in New Issue
Block a user