Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Used symbolic constants for psycopg2 isolation levels.

Django used the value 1 = ISOLATION_LEVEL_READ_UNCOMMITTED in some places, but
PostgreSQL doesn't provide "read uncommited", it uses "read committed" instead:
http://www.postgresql.org/docs/9.1/static/transaction-iso.html. For clarity,
this commit uses ISOLATION_LEVEL_READ_COMMITTED = 2 where 1 was previously used.



git-svn-id: http://code.djangoproject.com/svn/django/trunk@17112 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 549c495875d279c17fbd418238a305bcc51cdad6 1 parent e41e3a5
Aymeric Augustin authored November 19, 2011
12  django/db/backends/postgresql_psycopg2/base.py
@@ -108,7 +108,11 @@ def __init__(self, *args, **kwargs):
108 108
         self.features = DatabaseFeatures(self)
109 109
         autocommit = self.settings_dict["OPTIONS"].get('autocommit', False)
110 110
         self.features.uses_autocommit = autocommit
111  
-        self._set_isolation_level(int(not autocommit))
  111
+        if autocommit:
  112
+            level = psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT
  113
+        else:
  114
+            level = psycopg2.extensions.ISOLATION_LEVEL_READ_COMMITTED
  115
+        self._set_isolation_level(level)
112 116
         self.ops = DatabaseOperations(self)
113 117
         self.client = DatabaseClient(self)
114 118
         self.creation = DatabaseCreation(self)
@@ -189,7 +193,7 @@ def _enter_transaction_management(self, managed):
189 193
         the same transaction is visible across all the queries.
190 194
         """
191 195
         if self.features.uses_autocommit and managed and not self.isolation_level:
192  
-            self._set_isolation_level(1)
  196
+            self._set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_READ_COMMITTED)
193 197
 
194 198
     def _leave_transaction_management(self, managed):
195 199
         """
@@ -197,7 +201,7 @@ def _leave_transaction_management(self, managed):
197 201
         leaving transaction management.
198 202
         """
199 203
         if self.features.uses_autocommit and not managed and self.isolation_level:
200  
-            self._set_isolation_level(0)
  204
+            self._set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
201 205
 
202 206
     def _set_isolation_level(self, level):
203 207
         """
@@ -205,7 +209,7 @@ def _set_isolation_level(self, level):
205 209
         levels. This doesn't touch the uses_autocommit feature, since that
206 210
         controls the movement *between* isolation levels.
207 211
         """
208  
-        assert level in (0, 1)
  212
+        assert level in range(5)
209 213
         try:
210 214
             if self.connection is not None:
211 215
                 self.connection.set_isolation_level(level)
5  django/db/backends/postgresql_psycopg2/creation.py
... ...
@@ -1,3 +1,5 @@
  1
+import psycopg2.extensions
  2
+
1 3
 from django.db.backends.creation import BaseDatabaseCreation
2 4
 from django.db.backends.util import truncate_name
3 5
 
@@ -81,4 +83,5 @@ def set_autocommit(self):
81 83
     def _prepare_for_test_db_ddl(self):
82 84
         """Rollback and close the active transaction."""
83 85
         self.connection.connection.rollback()
84  
-        self.connection.connection.set_isolation_level(0)
  86
+        self.connection.connection.set_isolation_level(
  87
+                psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)

0 notes on commit 549c495

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