MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / begin

Method begin

lib/sqlalchemy/orm/session.py:5269–5289  ·  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

5267 self.class_ = type(class_.__name__, (class_,), {})
5268
5269 def begin(self) -> contextlib.AbstractContextManager[_S]:
5270 """Produce a context manager that both provides a new
5271 :class:`_orm.Session` as well as a transaction that commits.
5272
5273
5274 e.g.::
5275
5276 Session = sessionmaker(some_engine)
5277
5278 with Session.begin() as session:
5279 session.add(some_object)
5280
5281 # commits transaction, closes session
5282
5283 .. versionadded:: 1.4
5284
5285
5286 """
5287
5288 session = self()
5289 return session._maker_context_manager()
5290
5291 def __call__(self, **local_kw: Any) -> _S:
5292 """Produce a new :class:`.Session` object using the configuration

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected