Django

Code

Ticket #3460: psycopg2-commit-mode-r5790.diff

File psycopg2-commit-mode-r5790.diff, 1.5 kB (added by John Shaffer <jshaffer2112@gmail.com>, 1 year ago)

Updated patch for [5790]. The patch causes problems with fixtures and causes some of Django's tests to fail.

  • db/backends/postgresql_psycopg2/base.py

    old new  
    3434 
    3535    def cursor(self): 
    3636        from django.conf import settings 
    37         set_tz = False 
     37        first_cursor = False 
    3838        if self.connection is None: 
    39             set_tz = True 
     39            first_cursor = True 
    4040            if settings.DATABASE_NAME == '': 
    4141                from django.core.exceptions import ImproperlyConfigured 
    4242                raise ImproperlyConfigured, "You need to specify DATABASE_NAME in your Django settings file." 
     
    5050            if settings.DATABASE_PORT: 
    5151                conn_string += " port=%s" % settings.DATABASE_PORT 
    5252            self.connection = Database.connect(conn_string, **self.options) 
    53             self.connection.set_isolation_level(1) # make transactions transparent to all cursors 
     53            self.connection.set_isolation_level(0) # autocommit 
    5454            self.connection.set_client_encoding('UTF8') 
    5555        cursor = self.connection.cursor() 
    5656        cursor.tzinfo_factory = None 
    57         if set_tz
     57        if first_cursor
    5858            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) 
     59            cursor.execute("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED") 
     60            self._commit() 
    5961        global postgres_version 
    6062        if not postgres_version: 
    6163            cursor.execute("SELECT version()")