]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Implement proxy back reference system for asyncio
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 2 Jun 2021 16:23:31 +0000 (12:23 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 2 Jun 2021 20:09:14 +0000 (16:09 -0400)
commit97d922663a0350c6ce026ecfbde8010ca1bc0c37
tree438b4341441b33cee08b8f01022cd2ff383277f2
parentf51c56b8dca0569269a69bd85c25fcfed39a3c9e
Implement proxy back reference system for asyncio

Implemented a new registry architecture that allows the ``Async`` version
of an object, like ``AsyncSession``, ``AsyncConnection``, etc., to be
locatable given the proxied "sync" object, i.e. ``Session``,
``Connection``. Previously, to the degree such lookup functions were used,
an ``Async`` object would be re-created each time, which was less than
ideal as the identity and state of the "async" object would not be
preserved across calls.

From there, new helper functions :func:`_asyncio.async_object_session`,
:func:`_asyncio.async_session` as well as a new :class:`_orm.InstanceState`
attribute :attr:`_orm.InstanceState.asyncio_session` have been added, which
are used to retrieve the original :class:`_asyncio.AsyncSession` associated
with an ORM mapped object, a :class:`_orm.Session` associated with an
:class:`_asyncio.AsyncSession`, and an :class:`_asyncio.AsyncSession`
associated with an :class:`_orm.InstanceState`, respectively.

This patch also implements new methods
:meth:`_asyncio.AsyncSession.in_nested_transaction`,
:meth:`_asyncio.AsyncSession.get_transaction`,
:meth:`_asyncio.AsyncSession.get_nested_transaction`.

Fixes: #6319
Change-Id: Ia452a7e7ce9bad3ff8846c7dea8d45c839ac9fac
doc/build/changelog/unreleased_14/6319.rst [new file with mode: 0644]
doc/build/orm/extensions/asyncio.rst
lib/sqlalchemy/ext/asyncio/__init__.py
lib/sqlalchemy/ext/asyncio/base.py
lib/sqlalchemy/ext/asyncio/engine.py
lib/sqlalchemy/ext/asyncio/session.py
lib/sqlalchemy/orm/state.py
test/ext/asyncio/test_engine_py3k.py
test/ext/asyncio/test_session_py3k.py