@@ -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 ,
0 commit comments