Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Slight refactoring of isolation setting from r10029.

There was a bug in the way we were reading the DATABASE_OPTIONS setting
and a lot of essentially duplicated code. This is neater.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10033 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d4677d4bfbf73110a436037199b6938ce5ea167f 1 parent 90a3c34
Malcolm Tredinnick authored March 12, 2009
39  django/db/backends/postgresql_psycopg2/base.py
@@ -63,12 +63,9 @@ def __init__(self, *args, **kwargs):
63 63
         super(DatabaseWrapper, self).__init__(*args, **kwargs)
64 64
 
65 65
         self.features = DatabaseFeatures()
66  
-        if settings.DATABASE_OPTIONS.get('autocommit', False):
67  
-          self.features.uses_autocommit = True
68  
-          self._iso_level_0()
69  
-        else:
70  
-          self.features.uses_autocommit = False
71  
-          self._iso_level_1()
  66
+        autocommit = self.settings_dict["DATABASE_OPTIONS"].get('autocommit', False)
  67
+        self.features.uses_autocommit = autocommit
  68
+        self._set_isolation_level(int(not autocommit))
72 69
         self.ops = DatabaseOperations()
73 70
         self.client = DatabaseClient(self)
74 71
         self.creation = DatabaseCreation(self)
@@ -116,7 +113,7 @@ def _enter_transaction_management(self, managed):
116 113
         the same transaction is visible across all the queries.
117 114
         """
118 115
         if self.features.uses_autocommit and managed and not self.isolation_level:
119  
-            self._iso_level_1()
  116
+            self._set_isolation_level(1)
120 117
 
121 118
     def _leave_transaction_management(self, managed):
122 119
         """
@@ -124,29 +121,19 @@ def _leave_transaction_management(self, managed):
124 121
         leaving transaction management.
125 122
         """
126 123
         if self.features.uses_autocommit and not managed and self.isolation_level:
127  
-            self._iso_level_0()
  124
+            self._set_isolation_level(0)
128 125
 
129  
-    def _iso_level_0(self):
  126
+    def _set_isolation_level(self, level):
130 127
         """
131  
-        Do all the related feature configurations for isolation level 0. This
132  
-        doesn't touch the uses_autocommit feature, since that controls the
133  
-        movement *between* isolation levels.
  128
+        Do all the related feature configurations for changing isolation
  129
+        levels. This doesn't touch the uses_autocommit feature, since that
  130
+        controls the movement *between* isolation levels.
134 131
         """
  132
+        assert level in (0, 1)
135 133
         try:
136 134
             if self.connection is not None:
137  
-                self.connection.set_isolation_level(0)
  135
+                self.connection.set_isolation_level(level)
138 136
         finally:
139  
-            self.isolation_level = 0
140  
-            self.features.uses_savepoints = False
141  
-
142  
-    def _iso_level_1(self):
143  
-        """
144  
-        The "isolation level 1" version of _iso_level_0().
145  
-        """
146  
-        try:
147  
-            if self.connection is not None:
148  
-                self.connection.set_isolation_level(1)
149  
-        finally:
150  
-            self.isolation_level = 1
151  
-            self.features.uses_savepoints = True
  137
+            self.isolation_level = level
  138
+            self.features.uses_savepoints = bool(level)
152 139
 

0 notes on commit d4677d4

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