Commit 549c4958 authored by Aymeric Augustin's avatar Aymeric Augustin
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
parent e41e3a54
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -108,7 +108,11 @@ class DatabaseWrapper(BaseDatabaseWrapper):
        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 @@ class DatabaseWrapper(BaseDatabaseWrapper):
        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 @@ class DatabaseWrapper(BaseDatabaseWrapper):
        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 @@ class DatabaseWrapper(BaseDatabaseWrapper):
        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)
+4 −1
Original line number Diff line number Diff line
import psycopg2.extensions

from django.db.backends.creation import BaseDatabaseCreation
from django.db.backends.util import truncate_name

@@ -81,4 +83,5 @@ class DatabaseCreation(BaseDatabaseCreation):
    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)