diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-12-09 15:27:20 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-12-12 20:08:07 +0100 |
| commit | df30ae07fc7d7500bbbe51ed3361982f645169f2 (patch) | |
| tree | 6133d1d561fea70229d03a19578c625fccf121b9 /django/db | |
| parent | c7a19f42030c15ad3b3475ad9a4854e10733ff74 (diff) | |
Fixed postgis test database initialization
Refs #20968. Allow querying template_postgis presence without
existing test database.
Thanks Tim Graham for the review.
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/backends/__init__.py | 20 | ||||
| -rw-r--r-- | django/db/backends/creation.py | 20 |
2 files changed, 23 insertions, 17 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index ffe42e925d..bdf841cbd9 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -30,6 +30,8 @@ TableInfo = namedtuple('TableInfo', ['name', 'type']) FieldInfo = namedtuple('FieldInfo', 'name type_code display_size internal_size precision scale null_ok') +NO_DB_ALIAS = '__no_db__' + class BaseDatabaseWrapper(object): """ @@ -477,6 +479,24 @@ class BaseDatabaseWrapper(object): if must_close: self.close() + @cached_property + def _nodb_connection(self): + """ + 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. + Refs #10868, #17786, #16969. + """ + settings_dict = self.settings_dict.copy() + settings_dict['NAME'] = None + #backend = load_backend(settings_dict['ENGINE']) + nodb_connection = self.__class__( + settings_dict, + alias=NO_DB_ALIAS, + allow_thread_sharing=False) + return nodb_connection + def _start_transaction_under_autocommit(self): """ Only required when autocommits_when_autocommit_is_off = True. diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py index 18168deaca..d3def4ebe2 100644 --- a/django/db/backends/creation.py +++ b/django/db/backends/creation.py @@ -3,9 +3,7 @@ import sys import time from django.conf import settings -from django.db.utils import load_backend from django.utils.encoding import force_bytes -from django.utils.functional import cached_property from django.utils.six.moves import input from django.utils.six import StringIO from django.db import router @@ -17,7 +15,6 @@ from .utils import truncate_name # The prefix to put on the default database name when creating # the test database. TEST_DATABASE_PREFIX = 'test_' -NO_DB_ALIAS = '__no_db__' class BaseDatabaseCreation(object): @@ -34,23 +31,12 @@ class BaseDatabaseCreation(object): def __init__(self, connection): self.connection = connection - @cached_property + @property def _nodb_connection(self): """ - 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. - Refs #10868, #17786, #16969. + Used to be defined here, now moved to DatabaseWrapper. """ - settings_dict = self.connection.settings_dict.copy() - settings_dict['NAME'] = None - backend = load_backend(settings_dict['ENGINE']) - nodb_connection = backend.DatabaseWrapper( - settings_dict, - alias=NO_DB_ALIAS, - allow_thread_sharing=False) - return nodb_connection + return self.connection._nodb_connection @classmethod def _digest(cls, *args): |
