MCPcopy
hub / github.com/psycopg/psycopg / Transaction

Class Transaction

psycopg/psycopg/transaction.py:243–274  ·  view source on GitHub ↗

Returned by `Connection.transaction()` to handle a transaction block.

Source from the content-addressed store, hash-verified

241
242
243class Transaction(BaseTransaction["Connection[Any]"]):
244 """
245 Returned by `Connection.transaction()` to handle a transaction block.
246 """
247
248 __module__ = "psycopg"
249
250 @property
251 def connection(self) -> Connection[Any]:
252 """The connection the object is managing.
253
254 :type: `Connection`
255 """
256 return self._conn
257
258 def __enter__(self) -> Self:
259 with self._conn.lock:
260 self._conn.wait(self._enter_gen())
261 return self
262
263 def __exit__(
264 self,
265 exc_type: type[BaseException] | None,
266 exc_val: BaseException | None,
267 exc_tb: TracebackType | None,
268 ) -> bool:
269 if self.pgconn.status == OK:
270 with self._conn.lock:
271 return self._conn.wait(self._exit_gen(exc_type, exc_val, exc_tb))
272 else:
273 self.status = self.Status.FAILED
274 return False
275
276
277class AsyncTransaction(BaseTransaction["AsyncConnection[Any]"]):

Callers 1

transactionMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected