summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-09-18 14:29:47 -0400
committerTim Graham <timograham@gmail.com>2017-09-19 07:04:31 -0400
commitf7b0532ec0cf703849ef50e513e3dc6b5483a6b0 (patch)
treecc36e5bb5afcfa4941cb01e3b9df038061616a68
parente7adad27f30396823f3609fcb8699cefb25278bb (diff)
Refs #28334 -- Fixed crash in hstore/citext oid caching during test db creation.
-rw-r--r--django/contrib/postgres/signals.py3
-rw-r--r--tests/postgres_tests/test_signals.py8
2 files changed, 9 insertions, 2 deletions
diff --git a/django/contrib/postgres/signals.py b/django/contrib/postgres/signals.py
index 079aafe9c8..abfd89005d 100644
--- a/django/contrib/postgres/signals.py
+++ b/django/contrib/postgres/signals.py
@@ -5,6 +5,7 @@ from psycopg2 import ProgrammingError
from psycopg2.extras import register_hstore
from django.db import connections
+from django.db.backends.base.base import NO_DB_ALIAS
@functools.lru_cache()
@@ -34,7 +35,7 @@ def get_citext_oids(connection_alias):
def register_type_handlers(connection, **kwargs):
- if connection.vendor != 'postgresql':
+ if connection.vendor != 'postgresql' or connection.alias == NO_DB_ALIAS:
return
try:
diff --git a/tests/postgres_tests/test_signals.py b/tests/postgres_tests/test_signals.py
index a7112f014c..87d0f8bfa8 100644
--- a/tests/postgres_tests/test_signals.py
+++ b/tests/postgres_tests/test_signals.py
@@ -3,7 +3,9 @@ from django.db import connection
from . import PostgreSQLTestCase
try:
- from django.contrib.postgres.signals import get_hstore_oids, get_citext_oids
+ from django.contrib.postgres.signals import (
+ get_citext_oids, get_hstore_oids, register_type_handlers,
+ )
except ImportError:
pass # pyscogp2 isn't installed.
@@ -31,3 +33,7 @@ class OIDTests(PostgreSQLTestCase):
def test_citext_values(self):
oids = get_citext_oids(connection.alias)
self.assertOIDs(oids)
+
+ def test_register_type_handlers_no_db(self):
+ """Registering type handlers for the nodb connection does nothing."""
+ register_type_handlers(connection._nodb_connection)