This commit is contained in:
2025-05-22 20:25:38 +02:00
parent 09f6750c2b
commit ce03fbf12f
529 changed files with 3353 additions and 3312 deletions

View File

@@ -108,6 +108,7 @@ __all__ = ["scoped_session"]
"begin",
"begin_nested",
"close",
"reset",
"commit",
"connection",
"delete",
@@ -118,6 +119,7 @@ __all__ = ["scoped_session"]
"expunge_all",
"flush",
"get",
"get_one",
"get_bind",
"is_modified",
"bulk_save_objects",
@@ -466,7 +468,8 @@ class scoped_session(Generic[_S]):
:ref:`pysqlite_serializable` - special workarounds required
with the SQLite driver in order for SAVEPOINT to work
correctly.
correctly. For asyncio use cases, see the section
:ref:`aiosqlite_serializable`.
""" # noqa: E501
@@ -491,12 +494,17 @@ class scoped_session(Generic[_S]):
.. tip::
The :meth:`_orm.Session.close` method **does not prevent the
Session from being used again**. The :class:`_orm.Session` itself
does not actually have a distinct "closed" state; it merely means
In the default running mode the :meth:`_orm.Session.close`
method **does not prevent the Session from being used again**.
The :class:`_orm.Session` itself does not actually have a
distinct "closed" state; it merely means
the :class:`_orm.Session` will release all database connections
and ORM objects.
Setting the parameter :paramref:`_orm.Session.close_resets_only`
to ``False`` will instead make the ``close`` final, meaning that
any further action on the session will be forbidden.
.. versionchanged:: 1.4 The :meth:`.Session.close` method does not
immediately create a new :class:`.SessionTransaction` object;
instead, the new :class:`.SessionTransaction` is created only if
@@ -505,13 +513,49 @@ class scoped_session(Generic[_S]):
.. seealso::
:ref:`session_closing` - detail on the semantics of
:meth:`_orm.Session.close`
:meth:`_orm.Session.close` and :meth:`_orm.Session.reset`.
:meth:`_orm.Session.reset` - a similar method that behaves like
``close()`` with the parameter
:paramref:`_orm.Session.close_resets_only` set to ``True``.
""" # noqa: E501
return self._proxied.close()
def reset(self) -> None:
r"""Close out the transactional resources and ORM objects used by this
:class:`_orm.Session`, resetting the session to its initial state.
.. container:: class_bases
Proxied for the :class:`_orm.Session` class on
behalf of the :class:`_orm.scoping.scoped_session` class.
This method provides for same "reset-only" behavior that the
:meth:_orm.Session.close method has provided historically, where the
state of the :class:`_orm.Session` is reset as though the object were
brand new, and ready to be used again.
The method may then be useful for :class:`_orm.Session` objects
which set :paramref:`_orm.Session.close_resets_only` to ``False``,
so that "reset only" behavior is still available from this method.
.. versionadded:: 2.0.22
.. seealso::
:ref:`session_closing` - detail on the semantics of
:meth:`_orm.Session.close` and :meth:`_orm.Session.reset`.
:meth:`_orm.Session.close` - a similar method will additionally
prevent re-use of the Session when the parameter
:paramref:`_orm.Session.close_resets_only` is set to ``False``.
""" # noqa: E501
return self._proxied.reset()
def commit(self) -> None:
r"""Flush pending changes and commit the current transaction.
@@ -1028,6 +1072,56 @@ class scoped_session(Generic[_S]):
bind_arguments=bind_arguments,
)
def get_one(
self,
entity: _EntityBindKey[_O],
ident: _PKIdentityArgument,
*,
options: Optional[Sequence[ORMOption]] = None,
populate_existing: bool = False,
with_for_update: ForUpdateParameter = None,
identity_token: Optional[Any] = None,
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
) -> _O:
r"""Return exactly one instance based on the given primary key
identifier, or raise an exception if not found.
.. container:: class_bases
Proxied for the :class:`_orm.Session` class on
behalf of the :class:`_orm.scoping.scoped_session` class.
Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query
selects no rows.
For a detailed documentation of the arguments see the
method :meth:`.Session.get`.
.. versionadded:: 2.0.22
:return: The object instance.
.. seealso::
:meth:`.Session.get` - equivalent method that instead
returns ``None`` if no row was found with the provided primary
key
""" # noqa: E501
return self._proxied.get_one(
entity,
ident,
options=options,
populate_existing=populate_existing,
with_for_update=with_for_update,
identity_token=identity_token,
execution_options=execution_options,
bind_arguments=bind_arguments,
)
def get_bind(
self,
mapper: Optional[_EntityBindKey[_O]] = None,