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)
| 1949 | |
| 1950 | |
| 1951 | def async_object_session(instance: object) -> Optional[AsyncSession]: |
| 1952 | """Return the :class:`_asyncio.AsyncSession` to which the given instance |
| 1953 | belongs. |
| 1954 | |
| 1955 | This function makes use of the sync-API function |
| 1956 | :class:`_orm.object_session` to retrieve the :class:`_orm.Session` which |
| 1957 | refers to the given instance, and from there links it to the original |
| 1958 | :class:`_asyncio.AsyncSession`. |
| 1959 | |
| 1960 | If the :class:`_asyncio.AsyncSession` has been garbage collected, the |
| 1961 | return value is ``None``. |
| 1962 | |
| 1963 | This functionality is also available from the |
| 1964 | :attr:`_orm.InstanceState.async_session` accessor. |
| 1965 | |
| 1966 | :param instance: an ORM mapped instance |
| 1967 | :return: an :class:`_asyncio.AsyncSession` object, or ``None``. |
| 1968 | |
| 1969 | .. versionadded:: 1.4.18 |
| 1970 | |
| 1971 | """ |
| 1972 | |
| 1973 | session = object_session(instance) |
| 1974 | if session is not None: |
| 1975 | return async_session(session) |
| 1976 | else: |
| 1977 | return None |
| 1978 | |
| 1979 | |
| 1980 | def async_session(session: Session) -> Optional[AsyncSession]: |