summaryrefslogtreecommitdiff
path: root/django/db/backends/base/base.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2015-09-07 22:10:31 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2015-09-09 23:03:51 +0200
commit05cea7fdbbcd7bdcdc8d8162d95b1dd5d8195913 (patch)
treedebff1c4693e9a18ea3472f41603da207a449101 /django/db/backends/base/base.py
parente8b49d4cc4056716195f16963c9bb57e87952e0b (diff)
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.
Diffstat (limited to 'django/db/backends/base/base.py')
-rw-r--r--django/db/backends/base/base.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/django/db/backends/base/base.py b/django/db/backends/base/base.py
index 96ca0ccfde..2e6a528171 100644
--- a/django/db/backends/base/base.py
+++ b/django/db/backends/base/base.py
@@ -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)