Ticket #3460: autocommit-7624.patch

File autocommit-7624.patch, 4.2 KB (added by Collin Grady, 16 years ago)

added similar fix to postgresql backend for psycopg1

  • django/db/backends/postgresql/base.py

     
    8383    }
    8484
    8585    def _cursor(self, settings):
    86         set_tz = False
     86        first_cursor = False
    8787        if self.connection is None:
    88             set_tz = True
     88            first_cursor = True
    8989            if settings.DATABASE_NAME == '':
    9090                from django.core.exceptions import ImproperlyConfigured
    9191                raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.")
     
    9999            if settings.DATABASE_PORT:
    100100                conn_string += " port=%s" % settings.DATABASE_PORT
    101101            self.connection = Database.connect(conn_string, **self.options)
    102             self.connection.set_isolation_level(1) # make transactions transparent to all cursors
     102            self.connection.set_isolation_level(0)
    103103        cursor = self.connection.cursor()
    104         if set_tz:
     104        if first_cursor:
    105105            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
     106            cursor.execute("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED")
     107            self._commit()
    106108        cursor.execute("SET client_encoding to 'UNICODE'")
    107109        cursor = UnicodeCursorWrapper(cursor, 'utf-8')
    108110        return cursor
  • django/db/backends/postgresql_psycopg2/base.py

     
    5151    }
    5252
    5353    def _cursor(self, settings):
    54         set_tz = False
     54        first_cursor = False
    5555        if self.connection is None:
    56             set_tz = True
     56            first_cursor = True
    5757            if settings.DATABASE_NAME == '':
    5858                from django.core.exceptions import ImproperlyConfigured
    5959                raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.")
     
    6767            if settings.DATABASE_PORT:
    6868                conn_string += " port=%s" % settings.DATABASE_PORT
    6969            self.connection = Database.connect(conn_string, **self.options)
    70             self.connection.set_isolation_level(1) # make transactions transparent to all cursors
     70            self.connection.set_isolation_level(0)
    7171            self.connection.set_client_encoding('UTF8')
    7272        cursor = self.connection.cursor()
    7373        cursor.tzinfo_factory = None
    74         if set_tz:
     74        if first_cursor:
    7575            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
     76            cursor.execute("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED")
     77            self._commit()
    7678        return cursor
  • django/core/management/commands/loaddata.py

     
    99except NameError:
    1010    from sets import Set as set   # Python 2.3 fallback
    1111
     12def _set_transaction_mode(connection):
     13    "Make sure a connection is not in autocommit mode."
     14    if hasattr(connection.connection, "autocommit"):
     15        connection.connection.autocommit(False)
     16    elif hasattr(connection.connection, "set_isolation_level"):
     17        connection.connection.set_isolation_level(1)
     18
    1219class Command(BaseCommand):
    1320    option_list = BaseCommand.option_list + (
    1421        make_option('--verbosity', action='store', dest='verbosity', default='1',
     
    4148        # the side effect of initializing the test database (if
    4249        # it isn't already initialized).
    4350        cursor = connection.cursor()
     51        _set_transaction_mode(connection)
    4452
    4553        # Start transaction management. All fixtures are installed in a
    4654        # single transaction to ensure that all references are resolved.
     
    152160           
    153161        transaction.commit()
    154162        transaction.leave_transaction_management()
     163        connection.close()
    155164
    156165        if object_count == 0:
    157166            if verbosity > 1:
Back to Top