Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@aaugustin aaugustin authored
View
12 django/db/backends/postgresql_psycopg2/base.py
@@ -108,7 +108,11 @@ def __init__(self, *args, **kwargs):
self.features = DatabaseFeatures(self)
autocommit = self.settings_dict["OPTIONS"].get('autocommit', False)
self.features.uses_autocommit = autocommit
- self._set_isolation_level(int(not autocommit))
+ if autocommit:
+ level = psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT
+ else:
+ level = psycopg2.extensions.ISOLATION_LEVEL_READ_COMMITTED
+ self._set_isolation_level(level)
self.ops = DatabaseOperations(self)
self.client = DatabaseClient(self)
self.creation = DatabaseCreation(self)
@@ -189,7 +193,7 @@ def _enter_transaction_management(self, managed):
the same transaction is visible across all the queries.
"""
if self.features.uses_autocommit and managed and not self.isolation_level:
- self._set_isolation_level(1)
+ self._set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_READ_COMMITTED)
def _leave_transaction_management(self, managed):
"""
@@ -197,7 +201,7 @@ def _leave_transaction_management(self, managed):
leaving transaction management.
"""
if self.features.uses_autocommit and not managed and self.isolation_level:
- self._set_isolation_level(0)
+ self._set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
def _set_isolation_level(self, level):
"""
@@ -205,7 +209,7 @@ def _set_isolation_level(self, level):
levels. This doesn't touch the uses_autocommit feature, since that
controls the movement *between* isolation levels.
"""
- assert level in (0, 1)
+ assert level in range(5)
try:
if self.connection is not None:
self.connection.set_isolation_level(level)
View
5 django/db/backends/postgresql_psycopg2/creation.py
@@ -1,3 +1,5 @@
+import psycopg2.extensions
+
from django.db.backends.creation import BaseDatabaseCreation
from django.db.backends.util import truncate_name
@@ -81,4 +83,5 @@ def set_autocommit(self):
def _prepare_for_test_db_ddl(self):
"""Rollback and close the active transaction."""
self.connection.connection.rollback()
- self.connection.connection.set_isolation_level(0)
+ self.connection.connection.set_isolation_level(
+ psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
Please sign in to comment.
Something went wrong with that request. Please try again.