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

Method close

lib/sqlalchemy/orm/scoping.py:477–523  ·  view source on GitHub ↗

r"""Close out the transactional resources and ORM objects used by this :class:`_orm.Session`. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_orm.scoping.scoped_session` class. This expunges all ORM o

(self)

Source from the content-addressed store, hash-verified

475 return self._proxied.begin_nested()
476
477 def close(self) -> None:
478 r"""Close out the transactional resources and ORM objects used by this
479 :class:`_orm.Session`.
480
481 .. container:: class_bases
482
483 Proxied for the :class:`_orm.Session` class on
484 behalf of the :class:`_orm.scoping.scoped_session` class.
485
486 This expunges all ORM objects associated with this
487 :class:`_orm.Session`, ends any transaction in progress and
488 :term:`releases` any :class:`_engine.Connection` objects which this
489 :class:`_orm.Session` itself has checked out from associated
490 :class:`_engine.Engine` objects. The operation then leaves the
491 :class:`_orm.Session` in a state which it may be used again.
492
493 .. tip::
494
495 In the default running mode the :meth:`_orm.Session.close`
496 method **does not prevent the Session from being used again**.
497 The :class:`_orm.Session` itself does not actually have a
498 distinct "closed" state; it merely means
499 the :class:`_orm.Session` will release all database connections
500 and ORM objects.
501
502 Setting the parameter :paramref:`_orm.Session.close_resets_only`
503 to ``False`` will instead make the ``close`` final, meaning that
504 any further action on the session will be forbidden.
505
506 .. versionchanged:: 1.4 The :meth:`.Session.close` method does not
507 immediately create a new :class:`.SessionTransaction` object;
508 instead, the new :class:`.SessionTransaction` is created only if
509 the :class:`.Session` is used again for a database operation.
510
511 .. seealso::
512
513 :ref:`session_closing` - detail on the semantics of
514 :meth:`_orm.Session.close` and :meth:`_orm.Session.reset`.
515
516 :meth:`_orm.Session.reset` - a similar method that behaves like
517 ``close()`` with the parameter
518 :paramref:`_orm.Session.close_resets_only` set to ``True``.
519
520
521 """ # noqa: E501
522
523 return self._proxied.close()
524
525 def reset(self) -> None:
526 r"""Close out the transactional resources and ORM objects used by this

Callers 1

removeMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected