Ticket #3460: django-txpatch

File django-txpatch, 2.3 KB (added by nicferrier, 15 years ago)

patches dango's postgres backend for pg native autocommit

Line 
1--- /home/app/django-hg/django/db/transaction.py 2008-06-25 06:00:27.000000000 -0700
2+++ django/db/transaction.py 2009-01-05 06:25:50.000000000 -0800
3@@ -218,9 +218,11 @@
4 def _commit_manually(*args, **kw):
5 try:
6 enter_transaction_management()
7+ connection._enter_transaction_management()
8 managed(True)
9 return func(*args, **kw)
10 finally:
11+ connection._leave_transaction_management()
12 leave_transaction_management()
13
14 return wraps(func)(_commit_manually)
15--- /home/app/django-hg/django/db/backends/postgresql_psycopg2/base.py 2008-07-21 05:44:36.000000000 -0700
16+++ django/db/backends/postgresql_psycopg2/base.py 2009-01-05 06:25:50.000000000 -0800
17@@ -56,6 +56,26 @@
18 'iendswith': 'LIKE LOWER(%s)',
19 }
20
21+ def _enter_transaction_management(self):
22+ """Manages the mapping of transaction management to isolation levels"""
23+
24+ if getattr(self, '_isolation_level', 0) == 0:
25+ try:
26+ if self.connection != None:
27+ self.connection.set_isolation_level(1)
28+ finally:
29+ self._isolation_level = 1
30+
31+ def _leave_transaction_management(self):
32+ """Manages the mapping of transaction management to isolation levels"""
33+
34+ if getattr(self, '_isolation_level', 1) == 1:
35+ try:
36+ if self.connection != None:
37+ self.connection.set_isolation_level(0)
38+ finally:
39+ self._isolation_level = 0
40+
41 def _cursor(self, settings, *args, **kwargs):
42 first_cursor = False
43 if self.connection is None:
44@@ -73,8 +93,9 @@
45 if settings.DATABASE_PORT:
46 conn_string += " port=%s" % settings.DATABASE_PORT
47 self.connection = Database.connect(conn_string, **self.options)
48- self.connection.set_isolation_level(1) # make transactions transparent to all cursors
49 self.connection.set_client_encoding('UTF8')
50+ # make transactions transparent to all cursors
51+ self.connection.set_isolation_level(getattr(self, '_isolation_level', 0))
52 cursor = self.connection.cursor(*args, **kwargs)
53 cursor.tzinfo_factory = None
54 if first_cursor:
Back to Top