mirror of
https://github.com/langgenius/dify.git
synced 2025-11-30 12:53:33 +00:00
The `Account._current_tenant` object is loaded by a database session (typically `db.session`) whose lifetime is not aligned with the Account model instance. This misalignment causes a `DetachedInstanceError` to be raised when accessing attributes of `Account._current_tenant` after the original session has been closed. To resolve this issue, we now reload the tenant object with `expire_on_commit=False`, ensuring the tenant remains accessible even after the session is closed.