master
.sqladmin/models
def _run_query_sync(self, stmt: ClauseElement) -> Any:
with self.session_maker(expire_on_commit=False) as session:
result = session.execute(stmt)
return result.scalars().unique().all()
In the code, the use of a with ... as ... statement to manage the session led to an unexpected closure of the session, which may caused the following error in some case:
sqlalchemy.orm.exc.DetachedInstanceError:
This error occurs because closing the session detaches instances that still require the session for lazy loading or other operations.
To resolve this, I modified the code to manage the session explicitly, avoiding its premature closure. This change prevents the DetachedInstanceError by keeping the session open until all required operations are complete.
def _run_query_sync(self, stmt: ClauseElement) -> Any:
session = self.session_maker(expire_on_commit=False)
result = session.execute(stmt)
return result.scalars().unique().all()
With this modification, the error no longer occurs, and the instances remain attached to the session as needed.
No response
No response
No response
No response
Windows 10 / ptyhon 3.10.11 / sqladmin 0.16.1
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too