Changeset - a3df76ea9818
[Not reviewed]
0 1 0
Lance Edgar (lance) - 2 months ago 2024-09-03 11:13:15
lance@edbob.org
fix: move startup workaround for trainwreck query bug

apparently this workaround will break alembic commands since
versioning must be handled a bit differently in that scenario. so
must only do the workaround if versioning is enabled during the
startup sequence..
1 file changed with 17 insertions and 17 deletions:
0 comments (0 inline, 0 general)
rattail/config.py
Show inline comments
 
@@ -779,29 +779,29 @@ def make_config(
 
        from rattail.db.config import configure_versioning
 
        configure_versioning(config)
 

	
 
        # TODO: holy crap why is this needed?  without it, the first time
 
        # a trainwreck query happens, InvalidRequestError is raised.  but
 
        # this is clearly a trainwreck query, and yet no error if we do it
 
        # this early in the startup sequence?!  i have no idea what is
 
        # going on here but at least this "works" - fingers crossed..
 
        if getattr(config, 'trainwreck_engines', None):
 
            app = config.get_app()
 
            trainwreck = app.get_trainwreck_handler()
 
            try:
 
                trainwreck_model = trainwreck.get_model()
 
            except WuttaConfigurationError:
 
                pass
 
            else:
 
                trainwreck_session = trainwreck.make_session()
 
                trainwreck_session.query(trainwreck_model.Transaction).first()
 
                trainwreck_session.close()
 

	
 
    # maybe set "future" behavior for SQLAlchemy
 
    if config.get_bool('rattail.db.sqlalchemy_future_mode', usedb=False):
 
        from rattail.db import Session
 
        if Session:
 
            Session.configure(future=True)
 

	
 
    # TODO: holy crap why is this needed?  without it, the first time
 
    # a trainwreck query happens, InvalidRequestError is raised.  but
 
    # this is clearly a trainwreck query, and yet no error if we do it
 
    # this early in the startup sequence?!  i have no idea what is
 
    # going on here but at least this "works" - fingers crossed..
 
    if getattr(config, 'trainwreck_engines', None):
 
        app = config.get_app()
 
        trainwreck = app.get_trainwreck_handler()
 
        try:
 
            trainwreck_model = trainwreck.get_model()
 
        except WuttaConfigurationError:
 
            pass
 
        else:
 
            trainwreck_session = trainwreck.make_session()
 
            trainwreck_session.query(trainwreck_model.Transaction).first()
 
            trainwreck_session.close()
 

	
 
    return config
 

	
 

	
0 comments (0 inline, 0 general)