Skip to content

Commit 95068b7

Browse files
author
James William Pye
committed
Fix broken savepoint identification on RELEASE.
Add tests to make sure that it's never missed again.
1 parent 16a2f77 commit 95068b7

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

postgresql/documentation/changes.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changes
22
=======
33

4+
0.9.3
5+
-----
6+
7+
* Fix inconsistency in savepoint identification by pq3.Transaction.
8+
Savepoints via db.xact() were broken.
9+
[Reported by Elvis Pranskevichus]
10+
411
0.9.2 released on 2009-12-14
512
----------------------------
613

postgresql/driver/pq3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ def _start_xact_string(isolation = None, mode = None):
15001500

15011501
@staticmethod
15021502
def _savepoint_xact_string(id):
1503-
return 'SAVEPOINT "' + id.replace('"', '""') + '";'
1503+
return 'SAVEPOINT "xact(' + id.replace('"', '""') + ')";'
15041504

15051505
def start(self):
15061506
if self.state == 'open':
@@ -1609,7 +1609,7 @@ def commit(self):
16091609

16101610
@staticmethod
16111611
def _rollback_to_string(id):
1612-
return 'ROLLBACK TO "' + id.replace('"', '""') + '";'
1612+
return 'ROLLBACK TO "xact(' + id.replace('"', '""') + ')";'
16131613

16141614
def rollback(self):
16151615
if self.state == 'aborted':

postgresql/test/test_driver.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ def testProcExecutionInXact(self):
666666
with self.db.xact():
667667
self.testProcExecution()
668668

669+
def testProcExecutionInSubXact(self):
670+
with self.db.xact(), self.db.xact():
671+
self.testProcExecution()
672+
669673
def testNULL(self):
670674
# Directly commpare (SELECT NULL) is None
671675
self.failUnless(
@@ -1300,6 +1304,29 @@ def testFailedSubtransactionBlock(self):
13001304
# driver should have released/aborted instead
13011305
self.failUnlessEqual(err.source, 'CLIENT')
13021306

1307+
def testSuccessfulSubtransactionBlock(self):
1308+
with self.db.xact():
1309+
with self.db.xact():
1310+
self.db.execute("create temp table subxact_sx1(i int);")
1311+
with self.db.xact():
1312+
self.db.execute("create temp table subxact_sx2(i int);")
1313+
# And, because I'm paranoid.
1314+
# The following block is used to make sure
1315+
# that savepoints are actually being set.
1316+
try:
1317+
with self.db.xact():
1318+
self.db.execute("selekt 1")
1319+
except pg_exc.SyntaxError:
1320+
# Just in case the xact() aren't doing anything.
1321+
pass
1322+
with self.db.xact():
1323+
self.db.execute("create temp table subxact_sx3(i int);")
1324+
# if it can't drop these tables, it didn't manage the subxacts
1325+
# properly.
1326+
self.db.execute("drop table subxact_sx1")
1327+
self.db.execute("drop table subxact_sx2")
1328+
self.db.execute("drop table subxact_sx3")
1329+
13031330
def testCloseInSubTransactionBlock(self):
13041331
try:
13051332
with self.db.xact():

0 commit comments

Comments
 (0)