Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Implemented PostgreSQL version as a cached property.

  • Loading branch information...
commit 21765c0a6c7cece4d052c8c7af6022ac9c61b7cf 1 parent 7b8529d
Aymeric Augustin authored February 18, 2013
11  django/db/backends/postgresql_psycopg2/base.py
@@ -14,6 +14,7 @@
14 14
 from django.db.backends.postgresql_psycopg2.version import get_version
15 15
 from django.db.backends.postgresql_psycopg2.introspection import DatabaseIntrospection
16 16
 from django.utils.encoding import force_str
  17
+from django.utils.functional import cached_property
17 18
 from django.utils.safestring import SafeText, SafeBytes
18 19
 from django.utils import six
19 20
 from django.utils.timezone import utc
@@ -121,7 +122,6 @@ def __init__(self, *args, **kwargs):
121 122
         self.creation = DatabaseCreation(self)
122 123
         self.introspection = DatabaseIntrospection(self)
123 124
         self.validation = BaseDatabaseValidation(self)
124  
-        self._pg_version = None
125 125
 
126 126
     def check_constraints(self, table_names=None):
127 127
         """
@@ -150,11 +150,9 @@ def close(self):
150 150
             )
151 151
             raise
152 152
 
153  
-    def _get_pg_version(self):
154  
-        if self._pg_version is None:
155  
-            self._pg_version = get_version(self.connection)
156  
-        return self._pg_version
157  
-    pg_version = property(_get_pg_version)
  153
+    @cached_property
  154
+    def pg_version(self):
  155
+        return get_version(self.connection)
158 156
 
159 157
     def get_connection_params(self):
160 158
         settings_dict = self.settings_dict
@@ -202,7 +200,6 @@ def init_connection_state(self):
202 200
                 self.connection.cursor().execute(
203 201
                         self.ops.set_time_zone_sql(), [tz])
204 202
         self.connection.set_isolation_level(self.isolation_level)
205  
-        self._get_pg_version()
206 203
 
207 204
     def create_cursor(self):
208 205
         cursor = self.connection.cursor()

0 notes on commit 21765c0

Please sign in to comment.
Something went wrong with that request. Please try again.