summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Chainz <adam@adamj.eu>2015-09-10 17:47:50 +0100
committerClaude Paroz <claude@2xlibre.net>2015-09-11 08:40:43 +0200
commitb2f6e421a332ce45cf0f1f2f6bd5962765a013f1 (patch)
treef31a8304e9bd5f63a86f1696cd5a03e6ee644d4c
parentd3c92afe426c1e0a2223bb0296162dff4d1af585 (diff)
Fixed #25329 -- Prevented _nodb_connection from being left open
-rw-r--r--django/db/backends/base/base.py4
-rw-r--r--django/db/backends/postgresql/base.py2
-rw-r--r--tests/backends/tests.py2
3 files changed, 3 insertions, 5 deletions
diff --git a/django/db/backends/base/base.py b/django/db/backends/base/base.py
index 2e6a528171..0356ab54cc 100644
--- a/django/db/backends/base/base.py
+++ b/django/db/backends/base/base.py
@@ -569,10 +569,10 @@ class BaseDatabaseWrapper(object):
if must_close:
self.close()
- @cached_property
+ @property
def _nodb_connection(self):
"""
- Alternative connection to be used when there is no need to access
+ Return an alternative connection to be used when there is no need to access
the main database, specifically for test db creation/deletion.
This also prevents the production database from being exposed to
potential child threads while (or after) the test database is destroyed.
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index af616e48c4..383601e477 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -232,7 +232,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
else:
return True
- @cached_property
+ @property
def _nodb_connection(self):
nodb_connection = super(DatabaseWrapper, self)._nodb_connection
try:
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index c0af1bdb60..25f7432a46 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -173,12 +173,10 @@ class PostgreSQLTests(TestCase):
self.assertIsNone(nodb_conn.settings_dict['NAME'])
# Now assume the 'postgres' db isn't available
- del connection._nodb_connection
with warnings.catch_warnings(record=True) as w:
with mock.patch('django.db.backends.base.base.BaseDatabaseWrapper.connect',
side_effect=mocked_connect, autospec=True):
nodb_conn = connection._nodb_connection
- del connection._nodb_connection
self.assertIsNotNone(nodb_conn.settings_dict['NAME'])
self.assertEqual(nodb_conn.settings_dict['NAME'], connection.settings_dict['NAME'])
# Check a RuntimeWarning has been emitted