lol
This commit is contained in:
@@ -77,6 +77,7 @@ _T = TypeVar("_T", bound=Any)
|
||||
"begin",
|
||||
"begin_nested",
|
||||
"close",
|
||||
"reset",
|
||||
"commit",
|
||||
"connection",
|
||||
"delete",
|
||||
@@ -94,6 +95,8 @@ _T = TypeVar("_T", bound=Any)
|
||||
"rollback",
|
||||
"scalar",
|
||||
"scalars",
|
||||
"get",
|
||||
"get_one",
|
||||
"stream",
|
||||
"stream_scalars",
|
||||
],
|
||||
@@ -108,6 +111,7 @@ _T = TypeVar("_T", bound=Any)
|
||||
"no_autoflush",
|
||||
"info",
|
||||
],
|
||||
use_intermediate_variable=["get"],
|
||||
)
|
||||
class async_scoped_session(Generic[_AS]):
|
||||
"""Provides scoped management of :class:`.AsyncSession` objects.
|
||||
@@ -213,49 +217,6 @@ class async_scoped_session(Generic[_AS]):
|
||||
await self.registry().close()
|
||||
self.registry.clear()
|
||||
|
||||
async def get(
|
||||
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,
|
||||
) -> Optional[_O]:
|
||||
r"""Return an instance based on the given primary key identifier,
|
||||
or ``None`` if not found.
|
||||
|
||||
.. container:: class_bases
|
||||
|
||||
Proxied for the :class:`_asyncio.AsyncSession` class on
|
||||
behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:meth:`_orm.Session.get` - main documentation for get
|
||||
|
||||
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
# this was proxied but Mypy is requiring the return type to be
|
||||
# clarified
|
||||
|
||||
# work around:
|
||||
# https://github.com/python/typing/discussions/1143
|
||||
return_value = await self._proxied.get(
|
||||
entity,
|
||||
ident,
|
||||
options=options,
|
||||
populate_existing=populate_existing,
|
||||
with_for_update=with_for_update,
|
||||
identity_token=identity_token,
|
||||
execution_options=execution_options,
|
||||
)
|
||||
return return_value
|
||||
|
||||
# START PROXY METHODS async_scoped_session
|
||||
|
||||
# code within this block is **programmatically,
|
||||
@@ -433,6 +394,12 @@ class async_scoped_session(Generic[_AS]):
|
||||
For a general description of ORM begin nested, see
|
||||
:meth:`_orm.Session.begin_nested`.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`aiosqlite_serializable` - special workarounds required
|
||||
with the SQLite asyncio driver in order for SAVEPOINT to work
|
||||
correctly.
|
||||
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
@@ -447,34 +414,45 @@ class async_scoped_session(Generic[_AS]):
|
||||
Proxied for the :class:`_asyncio.AsyncSession` class on
|
||||
behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
|
||||
|
||||
This expunges all ORM objects associated with this
|
||||
:class:`_asyncio.AsyncSession`, ends any transaction in progress and
|
||||
:term:`releases` any :class:`_asyncio.AsyncConnection` objects which
|
||||
this :class:`_asyncio.AsyncSession` itself has checked out from
|
||||
associated :class:`_asyncio.AsyncEngine` objects. The operation then
|
||||
leaves the :class:`_asyncio.AsyncSession` in a state which it may be
|
||||
used again.
|
||||
|
||||
.. tip::
|
||||
|
||||
The :meth:`_asyncio.AsyncSession.close` method **does not prevent
|
||||
the Session from being used again**. The
|
||||
:class:`_asyncio.AsyncSession` itself does not actually have a
|
||||
distinct "closed" state; it merely means the
|
||||
:class:`_asyncio.AsyncSession` will release all database
|
||||
connections and ORM objects.
|
||||
|
||||
|
||||
.. seealso::
|
||||
|
||||
:meth:`_orm.Session.close` - main documentation for
|
||||
"close"
|
||||
|
||||
:ref:`session_closing` - detail on the semantics of
|
||||
:meth:`_asyncio.AsyncSession.close`
|
||||
:meth:`_asyncio.AsyncSession.close` and
|
||||
:meth:`_asyncio.AsyncSession.reset`.
|
||||
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
return await self._proxied.close()
|
||||
|
||||
async 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:`_asyncio.AsyncSession` class on
|
||||
behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
|
||||
|
||||
.. versionadded:: 2.0.22
|
||||
|
||||
.. seealso::
|
||||
|
||||
:meth:`_orm.Session.reset` - main documentation for
|
||||
"reset"
|
||||
|
||||
:ref:`session_closing` - detail on the semantics of
|
||||
:meth:`_asyncio.AsyncSession.close` and
|
||||
:meth:`_asyncio.AsyncSession.reset`.
|
||||
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
return await self._proxied.reset()
|
||||
|
||||
async def commit(self) -> None:
|
||||
r"""Commit the current transaction in progress.
|
||||
|
||||
@@ -483,6 +461,11 @@ class async_scoped_session(Generic[_AS]):
|
||||
Proxied for the :class:`_asyncio.AsyncSession` class on
|
||||
behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:meth:`_orm.Session.commit` - main documentation for
|
||||
"commit"
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
return await self._proxied.commit()
|
||||
@@ -1014,6 +997,11 @@ class async_scoped_session(Generic[_AS]):
|
||||
Proxied for the :class:`_asyncio.AsyncSession` class on
|
||||
behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:meth:`_orm.Session.rollback` - main documentation for
|
||||
"rollback"
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
return await self._proxied.rollback()
|
||||
@@ -1137,6 +1125,85 @@ class async_scoped_session(Generic[_AS]):
|
||||
**kw,
|
||||
)
|
||||
|
||||
async def get(
|
||||
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,
|
||||
) -> Union[_O, None]:
|
||||
r"""Return an instance based on the given primary key identifier,
|
||||
or ``None`` if not found.
|
||||
|
||||
.. container:: class_bases
|
||||
|
||||
Proxied for the :class:`_asyncio.AsyncSession` class on
|
||||
behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:meth:`_orm.Session.get` - main documentation for get
|
||||
|
||||
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
result = await self._proxied.get(
|
||||
entity,
|
||||
ident,
|
||||
options=options,
|
||||
populate_existing=populate_existing,
|
||||
with_for_update=with_for_update,
|
||||
identity_token=identity_token,
|
||||
execution_options=execution_options,
|
||||
)
|
||||
return result
|
||||
|
||||
async 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,
|
||||
) -> _O:
|
||||
r"""Return an instance based on the given primary key identifier,
|
||||
or raise an exception if not found.
|
||||
|
||||
.. container:: class_bases
|
||||
|
||||
Proxied for the :class:`_asyncio.AsyncSession` class on
|
||||
behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
|
||||
|
||||
Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query selects
|
||||
no rows.
|
||||
|
||||
..versionadded: 2.0.22
|
||||
|
||||
.. seealso::
|
||||
|
||||
:meth:`_orm.Session.get_one` - main documentation for get_one
|
||||
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
return await 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,
|
||||
)
|
||||
|
||||
@overload
|
||||
async def stream(
|
||||
self,
|
||||
@@ -1483,7 +1550,7 @@ class async_scoped_session(Generic[_AS]):
|
||||
return self._proxied.info
|
||||
|
||||
@classmethod
|
||||
async def close_all(self) -> None:
|
||||
async def close_all(cls) -> None:
|
||||
r"""Close all :class:`_asyncio.AsyncSession` sessions.
|
||||
|
||||
.. container:: class_bases
|
||||
@@ -1491,6 +1558,8 @@ class async_scoped_session(Generic[_AS]):
|
||||
Proxied for the :class:`_asyncio.AsyncSession` class on
|
||||
behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
|
||||
|
||||
.. deprecated:: 2.0 The :meth:`.AsyncSession.close_all` method is deprecated and will be removed in a future release. Please refer to :func:`_asyncio.close_all_sessions`.
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
return await AsyncSession.close_all()
|
||||
|
||||
Reference in New Issue
Block a user