diff --git a/django/contrib/gis/db/backends/postgis/base.py b/django/contrib/gis/db/backends/postgis/base.py index 23ec0553f82..8360c0e19a1 100644 --- a/django/contrib/gis/db/backends/postgis/base.py +++ b/django/contrib/gis/db/backends/postgis/base.py @@ -2,6 +2,15 @@ from functools import lru_cache from django.db.backends.base.base import NO_DB_ALIAS from django.db.backends.postgresql.base import DatabaseWrapper as PsycopgDatabaseWrapper +from django.db.backends.postgresql.features import ( + DatabaseFeatures as PsycopgDatabaseFeatures, +) +from django.db.backends.postgresql.introspection import ( + DatabaseIntrospection as PsycopgDatabaseIntrospection, +) +from django.db.backends.postgresql.operations import ( + DatabaseOperations as PsycopgDatabaseOperations, +) from django.db.backends.postgresql.psycopg_any import is_psycopg3 from .adapter import PostGISAdapter @@ -81,6 +90,9 @@ if is_psycopg3: class DatabaseWrapper(PsycopgDatabaseWrapper): SchemaEditorClass = PostGISSchemaEditor + features_class = DatabaseFeatures + ops_class = PostGISOperations + introspection_class = PostGISIntrospection _type_infos = { "geometry": {}, @@ -89,11 +101,13 @@ class DatabaseWrapper(PsycopgDatabaseWrapper): } def __init__(self, *args, **kwargs): + if kwargs.get("alias", "") == NO_DB_ALIAS: + # Don't initialize PostGIS-specific stuff for non-db connections. + self.features_class = PsycopgDatabaseFeatures + self.ops_class = PsycopgDatabaseOperations + self.introspection_class = PsycopgDatabaseIntrospection + super().__init__(*args, **kwargs) - if kwargs.get("alias", "") != NO_DB_ALIAS: - self.features = DatabaseFeatures(self) - self.ops = PostGISOperations(self) - self.introspection = PostGISIntrospection(self) def prepare_database(self): super().prepare_database()