Author: mtredinnick
Date: 2009-03-12 00:30:51 -0500 (Thu, 12 Mar 2009)
New Revision: 10033

Modified:
   django/trunk/django/db/backends/postgresql_psycopg2/base.py
Log:
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.

Modified: django/trunk/django/db/backends/postgresql_psycopg2/base.py
===================================================================
--- django/trunk/django/db/backends/postgresql_psycopg2/base.py 2009-03-11 
21:14:18 UTC (rev 10032)
+++ django/trunk/django/db/backends/postgresql_psycopg2/base.py 2009-03-12 
05:30:51 UTC (rev 10033)
@@ -63,12 +63,9 @@
         super(DatabaseWrapper, self).__init__(*args, **kwargs)
 
         self.features = DatabaseFeatures()
-        if settings.DATABASE_OPTIONS.get('autocommit', False):
-          self.features.uses_autocommit = True
-          self._iso_level_0()
-        else:
-          self.features.uses_autocommit = False
-          self._iso_level_1()
+        autocommit = self.settings_dict["DATABASE_OPTIONS"].get('autocommit', 
False)
+        self.features.uses_autocommit = autocommit
+        self._set_isolation_level(int(not autocommit))
         self.ops = DatabaseOperations()
         self.client = DatabaseClient(self)
         self.creation = DatabaseCreation(self)
@@ -116,7 +113,7 @@
         the same transaction is visible across all the queries.
         """
         if self.features.uses_autocommit and managed and not 
self.isolation_level:
-            self._iso_level_1()
+            self._set_isolation_level(1)
 
     def _leave_transaction_management(self, managed):
         """
@@ -124,29 +121,19 @@
         leaving transaction management.
         """
         if self.features.uses_autocommit and not managed and 
self.isolation_level:
-            self._iso_level_0()
+            self._set_isolation_level(0)
 
-    def _iso_level_0(self):
+    def _set_isolation_level(self, level):
         """
-        Do all the related feature configurations for isolation level 0. This
-        doesn't touch the uses_autocommit feature, since that controls the
-        movement *between* isolation levels.
+        Do all the related feature configurations for changing isolation
+        levels. This doesn't touch the uses_autocommit feature, since that
+        controls the movement *between* isolation levels.
         """
+        assert level in (0, 1)
         try:
             if self.connection is not None:
-                self.connection.set_isolation_level(0)
+                self.connection.set_isolation_level(level)
         finally:
-            self.isolation_level = 0
-            self.features.uses_savepoints = False
+            self.isolation_level = level
+            self.features.uses_savepoints = bool(level)
 
-    def _iso_level_1(self):
-        """
-        The "isolation level 1" version of _iso_level_0().
-        """
-        try:
-            if self.connection is not None:
-                self.connection.set_isolation_level(1)
-        finally:
-            self.isolation_level = 1
-            self.features.uses_savepoints = True
-


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to