Optionally configure SQLAlchemy Session with future=True

this avoids the need for setting `cascade_backrefs=False` everywhere

https://docs.sqlalchemy.org/en/14/errors.html#error-s9r1

https://docs.sqlalchemy.org/en/14/orm/session_api.html#sqlalchemy.orm.Session.params.future
This commit is contained in:
Lance Edgar 2023-09-10 07:44:13 -05:00
parent a9fbf48053
commit 64c58a3cf8

View file

@ -70,6 +70,10 @@ def make_rattail_config(settings):
if hasattr(rattail_config, 'tempmon_engine'): if hasattr(rattail_config, 'tempmon_engine'):
tailbone.db.TempmonSession.configure(bind=rattail_config.tempmon_engine) tailbone.db.TempmonSession.configure(bind=rattail_config.tempmon_engine)
# maybe set "future" behavior for SQLAlchemy
if rattail_config.getbool('rattail.db', 'sqlalchemy_future_mode', usedb=False):
tailbone.db.Session.configure(future=True)
# create session wrappers for each "extra" Trainwreck engine # create session wrappers for each "extra" Trainwreck engine
for key, engine in rattail_config.trainwreck_engines.items(): for key, engine in rattail_config.trainwreck_engines.items():
if key != 'default': if key != 'default':