Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 malcolmt authored
Showing with 13 additions and 26 deletions.
  1. +13 −26 django/db/backends/postgresql_psycopg2/base.py
39 django/db/backends/postgresql_psycopg2/base.py
View
@@ -63,12 +63,9 @@ def __init__(self, *args, **kwargs):
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 @@ 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._iso_level_1()
+ self._set_isolation_level(1)
def _leave_transaction_management(self, managed):
"""
@@ -124,29 +121,19 @@ def _leave_transaction_management(self, managed):
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
-
- 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
+ self.isolation_level = level
+ self.features.uses_savepoints = bool(level)
Please sign in to comment.
Something went wrong with that request. Please try again.