Skip to content

Commit 7ea2616

Browse files
author
James William Pye
committed
Mark as v1.1 and remove deprecated features.
1 parent 3129dcb commit 7ea2616

6 files changed

Lines changed: 12 additions & 194 deletions

File tree

postgresql/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ def __call__(self, *args, **kw) -> (object, Cursor, collections.Iterable):
598598
"""
599599

600600
##
601-
# Arguably, it would be wiser to isolate blocks, prepared transactions, and
602-
# savepoints, but the utility of the separation is not significant. It's really
601+
# Arguably, it would be wiser to isolate blocks, and savepoints, but the utility
602+
# of the separation is not significant. It's really
603603
# more interesting as a formality that the user may explicitly state the
604604
# type of the transaction. However, this capability is not completely absent
605605
# from the current interface as the configuration parameters, or lack thereof,

postgresql/documentation/copyman.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
Copy Management
55
***************
66

7-
.. warning:: `postgresql.copyman` is a new feature in v1.0.
8-
97
The `postgresql.copyman` module provides a way to quickly move COPY data coming
108
from one connection to many connections. Alternatively, it can be sourced
119
by arbitrary iterators and target arbitrary callables.

postgresql/documentation/notifyman.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
Notification Management
55
***********************
66

7-
.. warning:: `postgresql.notifyman` is a new feature in v1.0.
8-
97
Relevant SQL commands: `NOTIFY <http://postgresql.org/docs/current/static/sql-notify.html>`_,
108
`LISTEN <http://postgresql.org/docs/current/static/sql-listen.html>`_,
119
`UNLISTEN <http://postgresql.org/docs/current/static/sql-unlisten.html>`_.

postgresql/driver/pq3.py

Lines changed: 9 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,19 +2038,14 @@ class Transaction(pg_api.Transaction):
20382038

20392039
mode = None
20402040
isolation = None
2041-
gid = None
20422041

2043-
_e_factors = ('database', 'gid', 'isolation', 'mode')
2042+
_e_factors = ('database', 'isolation', 'mode')
20442043

20452044
def _e_metas(self):
20462045
yield (None, self.state)
20472046

2048-
def __init__(self, database, isolation = None, mode = None, gid = None):
2047+
def __init__(self, database, isolation = None, mode = None):
20492048
self.database = database
2050-
self.gid = gid
2051-
if gid is not None:
2052-
# XXX: remove in 1.1
2053-
warnings.warn("two phase interfaces will not exist in 1.1; do not use the 'gid' parameter", DeprecationWarning, stacklevel=3)
20542049
self.isolation = isolation
20552050
self.mode = mode
20562051
self.state = 'initialized'
@@ -2081,26 +2076,10 @@ def __exit__(self, typ, value, tb):
20812076
# If an error occurs, clean up the transaction state
20822077
# and raise as needed.
20832078
except pg_exc.ActiveTransactionError as err:
2084-
##
2085-
# Failed COMMIT PREPARED <gid>?
2086-
# Likely cases:
2087-
# - User exited block without preparing the transaction.
2088-
##
2089-
if not self.database.closed and self.gid is not None:
2079+
if not self.database.closed:
20902080
# adjust the state so rollback will do the right thing and abort.
20912081
self.state = 'open'
20922082
self.rollback()
2093-
##
2094-
# The other exception that *can* occur is
2095-
# UndefinedObjectError in which:
2096-
# - User issued C/RB P <gid> before exit, but not via xact methods.
2097-
# - User adjusted gid after prepare().
2098-
#
2099-
# But the occurrence of this exception means it's not in an active
2100-
# transaction, which means no cleanup other than raise is necessary.
2101-
err.details['cause'] = \
2102-
"The prepared transaction was not " \
2103-
"prepared prior to the block's exit."
21042083
raise
21052084
elif issubclass(typ, Exception):
21062085
# There's an exception, so only rollback if the connection
@@ -2146,7 +2125,7 @@ def start(self):
21462125
)
21472126
else:
21482127
self.type = 'savepoint'
2149-
if (self.gid, self.isolation, self.mode) != (None,None,None):
2128+
if (self.isolation, self.mode) != (None,None):
21502129
em = element.ClientError((
21512130
(b'S', 'ERROR'),
21522131
(b'C', '--OPE'),
@@ -2159,60 +2138,15 @@ def start(self):
21592138
self.state = 'open'
21602139
begin = start
21612140

2162-
@staticmethod
2163-
def _prepare_string(id):
2164-
"2pc prepared transaction 'gid'"
2165-
return "PREPARE TRANSACTION '" + id.replace("'", "''") + "';"
2166-
21672141
@staticmethod
21682142
def _release_string(id):
21692143
'release "";'
21702144
return 'RELEASE "xact(' + id.replace('"', '""') + ')";'
21712145

2172-
def prepare(self):
2173-
if self.state == 'prepared':
2174-
return
2175-
if self.state != 'open':
2176-
em = element.ClientError((
2177-
(b'S', 'ERROR'),
2178-
(b'C', '--OPE'),
2179-
(b'M', "transaction state must be 'open' in order to prepare"),
2180-
))
2181-
self.database.typio.raise_client_error(em, creator = self)
2182-
if self.type != 'block':
2183-
em = element.ClientError((
2184-
(b'S', 'ERROR'),
2185-
(b'C', '--OPE'),
2186-
(b'M', "improper transaction type to prepare"),
2187-
))
2188-
self.database.typio.raise_client_error(em, creator = self)
2189-
q = self._prepare_string(self.gid)
2190-
self.database.execute(q)
2191-
self.state = 'prepared'
2192-
2193-
def recover(self):
2194-
if self.state != 'initialized':
2195-
em = element.ClientError((
2196-
(b'S', 'ERROR'),
2197-
(b'C', '--OPE'),
2198-
(b'M', "improper state for prepared transaction recovery"),
2199-
))
2200-
self.database.typio.raise_client_error(em, creator = self)
2201-
if self.database.sys.xact_is_prepared(self.gid):
2202-
self.state = 'prepared'
2203-
self.type = 'block'
2204-
else:
2205-
em = element.ClientError((
2206-
(b'S', 'ERROR'),
2207-
(b'C', '42704'), # UndefinedObjectError
2208-
(b'M', "prepared transaction does not exist"),
2209-
))
2210-
self.database.typio.raise_client_error(em, creator = self)
2211-
22122146
def commit(self):
22132147
if self.state == 'committed':
22142148
return
2215-
if self.state not in ('prepared', 'open'):
2149+
if self.state != 'open':
22162150
em = element.ClientError((
22172151
(b'S', 'ERROR'),
22182152
(b'C', '--OPE'),
@@ -2221,19 +2155,8 @@ def commit(self):
22212155
self.database.typio.raise_client_error(em, creator = self)
22222156

22232157
if self.type == 'block':
2224-
if self.gid is not None:
2225-
# User better have prepared it.
2226-
q = "COMMIT PREPARED '" + self.gid.replace("'", "''") + "';"
2227-
else:
2228-
q = 'COMMIT'
2158+
q = 'COMMIT'
22292159
else:
2230-
if self.gid is not None:
2231-
em = element.ClientError((
2232-
(b'S', 'ERROR'),
2233-
(b'C', '--OPE'),
2234-
(b'M', "savepoint configured with global identifier"),
2235-
))
2236-
self.database.typio.raise_client_error(em, creator = self)
22372160
q = self._release_string(hex(id(self)))
22382161
self.database.execute(q)
22392162
self.state = 'committed'
@@ -2254,10 +2177,7 @@ def rollback(self):
22542177
self.database.typio.raise_client_error(em, creator = self)
22552178

22562179
if self.type == 'block':
2257-
if self.state == 'prepared':
2258-
q = "ROLLBACK PREPARED '" + self.gid.replace("'", "''") + "'"
2259-
else:
2260-
q = 'ABORT;'
2180+
q = 'ABORT;'
22612181
elif self.type == 'savepoint':
22622182
q = self._rollback_to_string(hex(id(self)))
22632183
else:
@@ -2339,8 +2259,8 @@ def do(self, language : str, source : str,
23392259
sql = "DO " + qlit(source) + " LANGUAGE " + qid(language) + ";"
23402260
self.execute(sql)
23412261

2342-
def xact(self, gid = None, isolation = None, mode = None):
2343-
x = Transaction(self, gid = gid, isolation = isolation, mode = mode)
2262+
def xact(self, isolation = None, mode = None):
2263+
x = Transaction(self, isolation = isolation, mode = mode)
23442264
return x
23452265

23462266
def prepare(self,

postgresql/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
# Set this to the target date when approaching a release.
1313
date = None
1414
tags = set(())
15-
version_info = (1, 0, 3)
15+
version_info = (1, 1, 0)
1616
version = '.'.join(map(str, version_info)) + (date is None and 'dev' or '')

postgresql/test/test_driver.py

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,104 +1404,6 @@ class SomeError(Exception):
14041404
db.execute, "SELECT * FROM withfoo"
14051405
)
14061406

1407-
@pg_tmp
1408-
def testPreparedTransactionCommit(self):
1409-
with db.xact(gid='commit_gid') as x:
1410-
db.execute("create table commit_gidtable as select 'foo'::text as t;")
1411-
x.prepare()
1412-
# not committed yet, so it better fail.
1413-
self.failUnlessRaises(pg_exc.UndefinedTableError,
1414-
db.execute, "select * from commit_gidtable"
1415-
)
1416-
# now it's committed.
1417-
self.failUnlessEqual(
1418-
db.prepare("select * FROM commit_gidtable").first(),
1419-
'foo',
1420-
)
1421-
db.execute('drop table commit_gidtable;')
1422-
1423-
@pg_tmp
1424-
def testWithUnpreparedTransaction(self):
1425-
try:
1426-
with db.xact(gid='not-gonna-prepare-it') as x:
1427-
pass
1428-
except pg_exc.ActiveTransactionError:
1429-
# *must* be okay to query again.
1430-
self.failUnlessEqual(db.prepare('select 1').first(), 1)
1431-
else:
1432-
self.fail("commit with gid succeeded unprepared..")
1433-
1434-
@pg_tmp
1435-
def testWithPreparedException(self):
1436-
class TheFailure(Exception):
1437-
pass
1438-
try:
1439-
with db.xact(gid='yeah,weprepare') as x:
1440-
x.prepare()
1441-
raise TheFailure()
1442-
except TheFailure as err:
1443-
# __exit__ should have issued ROLLBACK PREPARED, so let's find out.
1444-
# *must* be okay to query again.
1445-
self.failUnlessEqual(db.prepare('select 1').first(), 1)
1446-
x = db.xact(gid='yeah,weprepare')
1447-
self.failUnlessRaises(pg_exc.UndefinedObjectError, x.recover)
1448-
else:
1449-
self.fail("failure exception was not raised")
1450-
1451-
@pg_tmp
1452-
def testUnPreparedTransactionCommit(self):
1453-
x = db.xact(gid='never_prepared')
1454-
x.start()
1455-
self.failUnlessRaises(pg_exc.ActiveTransactionError, x.commit)
1456-
self.failUnlessRaises(pg_exc.InFailedTransactionError, x.commit)
1457-
1458-
@pg_tmp
1459-
def testPreparedTransactionRollback(self):
1460-
x = db.xact(gid='rollback_gid')
1461-
x.start()
1462-
db.execute("create table gidtable as select 'foo'::text as t;")
1463-
x.prepare()
1464-
x.rollback()
1465-
self.failUnlessRaises(
1466-
pg_exc.UndefinedTableError,
1467-
db.execute, "select * from gidtable"
1468-
)
1469-
1470-
@pg_tmp
1471-
def testPreparedTransactionRecovery(self):
1472-
x = db.xact(gid='recover dis')
1473-
x.start()
1474-
db.execute("create table distable (i int);")
1475-
x.prepare()
1476-
del x
1477-
x = db.xact(gid='recover dis')
1478-
x.recover()
1479-
x.commit()
1480-
db.execute("drop table distable;")
1481-
1482-
@pg_tmp
1483-
def testPreparedTransactionRecoveryAbort(self):
1484-
x = db.xact(gid='recover dis abort')
1485-
x.start()
1486-
db.execute("create table distableabort (i int);")
1487-
x.prepare()
1488-
del x
1489-
x = db.xact(gid='recover dis abort')
1490-
x.recover()
1491-
x.rollback()
1492-
self.failUnlessRaises(
1493-
pg_exc.UndefinedTableError,
1494-
db.execute, "select * from distableabort"
1495-
)
1496-
1497-
@pg_tmp
1498-
def testPreparedTransactionFailedRecovery(self):
1499-
x = db.xact(gid="NO XACT HERE")
1500-
self.failUnlessRaises(
1501-
pg_exc.UndefinedObjectError,
1502-
x.recover
1503-
)
1504-
15051407
@pg_tmp
15061408
def testSerializeable(self):
15071409
with db.connector() as db2:

0 commit comments

Comments
 (0)