diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index fb1ad5f991..831ad84843 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -14,6 +14,7 @@ from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation from django.db.backends.postgresql_psycopg2.version import get_version from django.db.backends.postgresql_psycopg2.introspection import DatabaseIntrospection from django.utils.encoding import force_str +from django.utils.functional import cached_property from django.utils.safestring import SafeText, SafeBytes from django.utils import six from django.utils.timezone import utc @@ -121,7 +122,6 @@ class DatabaseWrapper(BaseDatabaseWrapper): self.creation = DatabaseCreation(self) self.introspection = DatabaseIntrospection(self) self.validation = BaseDatabaseValidation(self) - self._pg_version = None def check_constraints(self, table_names=None): """ @@ -150,11 +150,9 @@ class DatabaseWrapper(BaseDatabaseWrapper): ) raise - def _get_pg_version(self): - if self._pg_version is None: - self._pg_version = get_version(self.connection) - return self._pg_version - pg_version = property(_get_pg_version) + @cached_property + def pg_version(self): + return get_version(self.connection) def get_connection_params(self): settings_dict = self.settings_dict @@ -202,7 +200,6 @@ class DatabaseWrapper(BaseDatabaseWrapper): self.connection.cursor().execute( self.ops.set_time_zone_sql(), [tz]) self.connection.set_isolation_level(self.isolation_level) - self._get_pg_version() def create_cursor(self): cursor = self.connection.cursor()