1
0
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:
Aymeric Augustin
2015-09-07 22:10:31 +02:00
parent e8b49d4cc4
commit 05cea7fdbb
4 changed files with 27 additions and 27 deletions

View File

@@ -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)