You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I spent a good deal of time today working through this problem, and I figured I should document it here. The error becomes apparent when a user tries to flush objects that are versioned, but the session is not being tracked by the versioning_manager. A KeyError exception is raised as the session is not in versioning_manager.units_of_work.
make_versioned by default uses the default session factory for sqlalchemy (sqlalchemy.orm.session.Session). This behavior cannot be overridden either – versioning_manager.track_session(...) is called for whatever value is provided (i.e. None is not allowed, as an exception is thrown).
This is probably not a good idea, as common practices like dependency-injection break this. An example would be if a user is to generate his own session factory using sqlalchemy.orm.session.sessionmaker (as is encouraged).
Anyway, the solution here is to call versioning_manager.track_session(my_session_factory) with the my_session_factory the user has generated from sessionmaker.
The text was updated successfully, but these errors were encountered:
I also came across this issue when using SQLAlchemy-Continuum==1.3.6 with Flask, the FlaskPlugin and Flask-SQLAlchemy.
I found the best way around this was to pass the session factory at creation of the make_versioned class; make_versioned(session=db.session, plugins=[FlaskPlugin()])
Maybe the docs the docs should be updated to state that you need to explicitly pass the session factory if you are not using the default factory?
This was happening due to the bug in sqlalchemy: sqlalchemy/sqlalchemy#8467
This ticket can be closed as sqlalchemt 1.4.41 is released which fixes this bug
I spent a good deal of time today working through this problem, and I figured I should document it here. The error becomes apparent when a user tries to flush objects that are versioned, but the session is not being tracked by the versioning_manager. A
KeyError
exception is raised as the session is not inversioning_manager.units_of_work
.make_versioned
by default uses the default session factory for sqlalchemy (sqlalchemy.orm.session.Session
). This behavior cannot be overridden either –versioning_manager.track_session(...)
is called for whatever value is provided (i.e.None
is not allowed, as an exception is thrown).This is probably not a good idea, as common practices like dependency-injection break this. An example would be if a user is to generate his own session factory using
sqlalchemy.orm.session.sessionmaker
(as is encouraged).Anyway, the solution here is to call
versioning_manager.track_session(my_session_factory)
with themy_session_factory
the user has generated fromsessionmaker
.The text was updated successfully, but these errors were encountered: