Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented PostgreSQL version as a cached property.

  • Loading branch information...
commit 21765c0a6c7cece4d052c8c7af6022ac9c61b7cf 1 parent 7b8529d
@aaugustin aaugustin authored
Showing with 4 additions and 7 deletions.
  1. +4 −7 django/db/backends/postgresql_psycopg2/base.py
View
11 django/db/backends/postgresql_psycopg2/base.py
@@ -14,6 +14,7 @@
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 @@ def __init__(self, *args, **kwargs):
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 @@ def close(self):
)
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 @@ def init_connection_state(self):
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()
Please sign in to comment.
Something went wrong with that request. Please try again.