Skip to content

Commit 128ee90

Browse files
author
James William Pye
committed
Release rolled back savepoints.
fixes #45
1 parent e352a3a commit 128ee90

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

postgresql/driver/pq3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,8 +2169,8 @@ def commit(self):
21692169
self.state = 'committed'
21702170

21712171
@staticmethod
2172-
def _rollback_to_string(id):
2173-
return 'ROLLBACK TO "xact(' + id.replace('"', '""') + ')";'
2172+
def _rollback_to_string(id, fmt = 'ROLLBACK TO "xact({0})"; RELEASE "xact({0})";'.format):
2173+
return fmt(id.replace('"', '""'))
21742174

21752175
def rollback(self):
21762176
if self.state == 'aborted':

postgresql/test/test_driver.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,23 @@ def testSuccessfulSubtransactionBlock(self):
15101510
db.execute("drop table subxact_sx2")
15111511
db.execute("drop table subxact_sx3")
15121512

1513+
@pg_tmp
1514+
def testReleasedSavepoint(self):
1515+
# validate that the rolled back savepoint is released as well.
1516+
x = None
1517+
with db.xact():
1518+
try:
1519+
with db.xact():
1520+
try:
1521+
with db.xact() as x:
1522+
db.execute("selekt 1")
1523+
except pg_exc.SyntaxError:
1524+
db.execute('RELEASE "xact(' + hex(id(x)) + ')"')
1525+
except pg_exc.InvalidSavepointSpecificationError as e:
1526+
pass
1527+
else:
1528+
self.fail("InvalidSavepointSpecificationError not raised")
1529+
15131530
@pg_tmp
15141531
def testCloseInSubTransactionBlock(self):
15151532
try:

0 commit comments

Comments
 (0)