Reputation: 1550
I am using SQLAlchemy with an async driver. I am investigating on the possibility to load related objects using AsyncAttrs
/awaitable_attrs
according to Pydantic/SQLModel models.
What are exactly the performance implications of using awaitable_attrs
to load relationships? The documentation on that matter confuses me:
The AsyncAttrs.awaitable_attrs performs a call against the attribute that is approximately equivalent to using the AsyncSession.run_sync() method, e.g.:
for b1 in await async_session.run_sync(lambda sess: a1.bs): print(b1)
Moreover, the documentation on AsyncSession.run_sync()
states:
The provided callable is invoked inline within the asyncio event loop, and will block on traditional IO calls. IO within this callable should only call into SQLAlchemy’s asyncio database APIs which will be properly adapted to the greenlet context.
It is clear that loading an unloaded relationship emits I/O to the database, but is it blocking the event loop while doing so? Additionally, are relationships that are already loaded (through eager loading) queried again?
Upvotes: 2
Views: 476