Code

Ticket #3460: combined.diff

File combined.diff, 1.5 KB (added by Jack Moffitt <metajack@…>, 7 years ago)

updated patch; also fixes #3459

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