MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / __init__

Method __init__

lib/sqlalchemy/orm/session.py:938–979  ·  view source on GitHub ↗
(
        self,
        session: Session,
        origin: SessionTransactionOrigin,
        parent: Optional[SessionTransaction] = None,
    )

Source from the content-addressed store, hash-verified

936 """
937
938 def __init__(
939 self,
940 session: Session,
941 origin: SessionTransactionOrigin,
942 parent: Optional[SessionTransaction] = None,
943 ):
944 TransactionalContext._trans_ctx_check(session)
945
946 self.session = session
947 self._connections = {}
948 self._parent = parent
949 self.nested = nested = origin is SessionTransactionOrigin.BEGIN_NESTED
950 self.origin = origin
951
952 if session._close_state is _SessionCloseState.CLOSED:
953 raise sa_exc.InvalidRequestError(
954 "This Session has been permanently closed and is unable "
955 "to handle any more transaction requests."
956 )
957
958 if nested:
959 if not parent:
960 raise sa_exc.InvalidRequestError(
961 "Can't start a SAVEPOINT transaction when no existing "
962 "transaction is in progress"
963 )
964
965 self._previous_nested_transaction = session._nested_transaction
966 elif origin is SessionTransactionOrigin.SUBTRANSACTION:
967 assert parent is not None
968 else:
969 assert parent is None
970
971 self._state = SessionTransactionState.ACTIVE
972
973 self._take_snapshot()
974
975 # make sure transaction is assigned before we call the
976 # dispatch
977 self.session._transaction = self
978
979 self.session.dispatch.after_transaction_create(self.session, self)
980
981 def _raise_for_prerequisite_state(
982 self, operation_name: str, state: _StateChangeState

Callers

nothing calls this directly

Calls 3

_take_snapshotMethod · 0.95
_trans_ctx_checkMethod · 0.80

Tested by

no test coverage detected