MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / __init__

Method __init__

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

Source from the content-addressed store, hash-verified

925 """
926
927 def __init__(
928 self,
929 session: Session,
930 origin: SessionTransactionOrigin,
931 parent: Optional[SessionTransaction] = None,
932 ):
933 TransactionalContext._trans_ctx_check(session)
934
935 self.session = session
936 self._connections = {}
937 self._parent = parent
938 self.nested = nested = origin is SessionTransactionOrigin.BEGIN_NESTED
939 self.origin = origin
940
941 if session._close_state is _SessionCloseState.CLOSED:
942 raise sa_exc.InvalidRequestError(
943 "This Session has been permanently closed and is unable "
944 "to handle any more transaction requests."
945 )
946
947 if nested:
948 if not parent:
949 raise sa_exc.InvalidRequestError(
950 "Can't start a SAVEPOINT transaction when no existing "
951 "transaction is in progress"
952 )
953
954 self._previous_nested_transaction = session._nested_transaction
955 elif origin is SessionTransactionOrigin.SUBTRANSACTION:
956 assert parent is not None
957 else:
958 assert parent is None
959
960 self._state = SessionTransactionState.ACTIVE
961
962 self._take_snapshot()
963
964 # make sure transaction is assigned before we call the
965 # dispatch
966 self.session._transaction = self
967
968 self.session.dispatch.after_transaction_create(self.session, self)
969
970 def _raise_for_prerequisite_state(
971 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