--- /home/app/django-hg/django/db/transaction.py 2008-06-25 06:00:27.000000000 -0700 +++ django/db/transaction.py 2009-01-05 06:25:50.000000000 -0800 @@ -218,9 +218,11 @@ def _commit_manually(*args, **kw): try: enter_transaction_management() + connection._enter_transaction_management() managed(True) return func(*args, **kw) finally: + connection._leave_transaction_management() leave_transaction_management() return wraps(func)(_commit_manually) --- /home/app/django-hg/django/db/backends/postgresql_psycopg2/base.py 2008-07-21 05:44:36.000000000 -0700 +++ django/db/backends/postgresql_psycopg2/base.py 2009-01-05 06:25:50.000000000 -0800 @@ -56,6 +56,26 @@ 'iendswith': 'LIKE LOWER(%s)', } + def _enter_transaction_management(self): + """Manages the mapping of transaction management to isolation levels""" + + if getattr(self, '_isolation_level', 0) == 0: + try: + if self.connection != None: + self.connection.set_isolation_level(1) + finally: + self._isolation_level = 1 + + def _leave_transaction_management(self): + """Manages the mapping of transaction management to isolation levels""" + + if getattr(self, '_isolation_level', 1) == 1: + try: + if self.connection != None: + self.connection.set_isolation_level(0) + finally: + self._isolation_level = 0 + def _cursor(self, settings, *args, **kwargs): first_cursor = False if self.connection is None: @@ -73,8 +93,9 @@ if settings.DATABASE_PORT: conn_string += " port=%s" % settings.DATABASE_PORT self.connection = Database.connect(conn_string, **self.options) - self.connection.set_isolation_level(1) # make transactions transparent to all cursors self.connection.set_client_encoding('UTF8') + # make transactions transparent to all cursors + self.connection.set_isolation_level(getattr(self, '_isolation_level', 0)) cursor = self.connection.cursor(*args, **kwargs) cursor.tzinfo_factory = None if first_cursor: