Passing expire_on_commit=False on sessionmaker() [see #181]

Accessing db objects outside of their session seems to fail on SQLAlchemy >= 1.4
with a `Instance `Instance <x> is not bound to a Session` error.

Setting expire_on_commit=False on the session seems to somehow fix the issue
(see https://stackoverflow.com/questions/3039567/sqlalchemy-detachedinstanceerror-with-regular-attribute-not-a-relation)
This commit is contained in:
Fabio Manganiello 2021-03-25 20:30:36 +01:00
parent 4313b6e883
commit 570f1d0cf6

View file

@ -234,7 +234,7 @@ class UserManager:
def _get_db_session(self): def _get_db_session(self):
Base.metadata.create_all(self._engine) Base.metadata.create_all(self._engine)
session = scoped_session(sessionmaker()) session = scoped_session(sessionmaker(expire_on_commit=False))
session.configure(bind=self._engine) session.configure(bind=self._engine)
return session() return session()