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

Method begin

lib/sqlalchemy/orm/session.py:5105–5125  ·  view source on GitHub ↗

Produce a context manager that both provides a new :class:`_orm.Session` as well as a transaction that commits. e.g.:: Session = sessionmaker(some_engine) with Session.begin() as session: session.add(some_object) # commits tran

(self)

Source from the content-addressed store, hash-verified

5103 self.class_ = type(class_.__name__, (class_,), {})
5104
5105 def begin(self) -> contextlib.AbstractContextManager[_S]:
5106 """Produce a context manager that both provides a new
5107 :class:`_orm.Session` as well as a transaction that commits.
5108
5109
5110 e.g.::
5111
5112 Session = sessionmaker(some_engine)
5113
5114 with Session.begin() as session:
5115 session.add(some_object)
5116
5117 # commits transaction, closes session
5118
5119 .. versionadded:: 1.4
5120
5121
5122 """
5123
5124 session = self()
5125 return session._maker_context_manager()
5126
5127 def __call__(self, **local_kw: Any) -> _S:
5128 """Produce a new :class:`.Session` object using the configuration

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected