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

Function async_object_session

lib/sqlalchemy/ext/asyncio/session.py:1891–1917  ·  view source on GitHub ↗

Return the :class:`_asyncio.AsyncSession` to which the given instance belongs. This function makes use of the sync-API function :class:`_orm.object_session` to retrieve the :class:`_orm.Session` which refers to the given instance, and from there links it to the original :class:`

(instance: object)

Source from the content-addressed store, hash-verified

1889
1890
1891def async_object_session(instance: object) -> Optional[AsyncSession]:
1892 """Return the :class:`_asyncio.AsyncSession` to which the given instance
1893 belongs.
1894
1895 This function makes use of the sync-API function
1896 :class:`_orm.object_session` to retrieve the :class:`_orm.Session` which
1897 refers to the given instance, and from there links it to the original
1898 :class:`_asyncio.AsyncSession`.
1899
1900 If the :class:`_asyncio.AsyncSession` has been garbage collected, the
1901 return value is ``None``.
1902
1903 This functionality is also available from the
1904 :attr:`_orm.InstanceState.async_session` accessor.
1905
1906 :param instance: an ORM mapped instance
1907 :return: an :class:`_asyncio.AsyncSession` object, or ``None``.
1908
1909 .. versionadded:: 1.4.18
1910
1911 """
1912
1913 session = object_session(instance)
1914 if session is not None:
1915 return async_session(session)
1916 else:
1917 return None
1918
1919
1920def async_session(session: Session) -> Optional[AsyncSession]:

Calls 2

object_sessionFunction · 0.85
async_sessionFunction · 0.85