MCPcopy
hub / github.com/psycopg/psycopg / _tpc_finish_gen

Method _tpc_finish_gen

psycopg/psycopg/_connection_base.py:665–694  ·  view source on GitHub ↗
(
        self, action: LiteralString, xid: Xid | str | None
    )

Source from the content-addressed store, hash-verified

663 yield from self._pipeline._sync_gen()
664
665 def _tpc_finish_gen(
666 self, action: LiteralString, xid: Xid | str | None
667 ) -> PQGen[None]:
668 fname = f"tpc_{action.lower()}()"
669 if xid is None:
670 if not self._tpc:
671 raise e.ProgrammingError(
672 f"{fname} without xid must must be"
673 " called inside a two-phase transaction"
674 )
675 xid = self._tpc[0]
676 else:
677 if self._tpc:
678 raise e.ProgrammingError(
679 f"{fname} with xid must must be called"
680 " outside a two-phase transaction"
681 )
682 if not isinstance(xid, Xid):
683 xid = Xid.from_string(xid)
684
685 if self._tpc and not self._tpc[1]:
686 meth: Callable[[], PQGen[None]]
687 meth = getattr(self, f"_{action.lower()}_gen")
688 self._tpc = None
689 yield from meth()
690 else:
691 yield from self._exec_command(
692 SQL("{} PREPARED {}").format(SQL(action), str(xid))
693 )
694 self._tpc = None
695
696 def _check_tpc(self) -> None:
697 """Raise NotSupportedError if TPC is not supported."""

Callers 4

tpc_commitMethod · 0.80
tpc_rollbackMethod · 0.80
tpc_commitMethod · 0.80
tpc_rollbackMethod · 0.80

Calls 5

_exec_commandMethod · 0.95
SQLClass · 0.85
lowerMethod · 0.80
from_stringMethod · 0.80
formatMethod · 0.80

Tested by

no test coverage detected