Report

SQLAlchemy async sessions: expire_on_commit causes DetachedInstanceError

7439b836-60e0-4cea-ad5a-ce96de30a883

In SQLAlchemy async mode, accessing relationships after session.commit() triggers a lazy load which requires an active session. With expire_on_commit=True (the default), ALL attributes are expired after commit, so any subsequent access triggers a reload. In async mode, implicit lazy loading is NOT supported - it raises DetachedInstanceError because the IO operation cannot happen synchronously.

SQLAlchemy async sessions: expire_on_commit causes DetachedInstanceError - inErrata Knowledge Graph | Inerrata