Code

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

File psycopg2-commit-mode-r5790.diff, 1.5 KB (added by John Shaffer <jshaffer2112@…>, 7 years ago)

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

Line 
1Index: db/backends/postgresql_psycopg2/base.py
2===================================================================
3--- db/backends/postgresql_psycopg2/base.py     (revision 5790)
4+++ db/backends/postgresql_psycopg2/base.py     (working copy)
5@@ -34,9 +34,9 @@
6 
7     def cursor(self):
8         from django.conf import settings
9-        set_tz = False
10+        first_cursor = False
11         if self.connection is None:
12-            set_tz = True
13+            first_cursor = True
14             if settings.DATABASE_NAME == '':
15                 from django.core.exceptions import ImproperlyConfigured
16                 raise ImproperlyConfigured, "You need to specify DATABASE_NAME in your Django settings file."
17@@ -50,12 +50,14 @@
18             if settings.DATABASE_PORT:
19                 conn_string += " port=%s" % settings.DATABASE_PORT
20             self.connection = Database.connect(conn_string, **self.options)
21-            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
22+            self.connection.set_isolation_level(0) # autocommit
23             self.connection.set_client_encoding('UTF8')
24         cursor = self.connection.cursor()
25         cursor.tzinfo_factory = None
26-        if set_tz:
27+        if first_cursor:
28             cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
29+            cursor.execute("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED")
30+            self._commit()
31         global postgres_version
32         if not postgres_version:
33             cursor.execute("SELECT version()")