True. I should have modified def run_migrations_online(): """Run migrations in 'online' mode.
In this scenario we need to create an Engine and associate a connection with the context. """ engine = engine_from_config( config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) connection = engine.connect() to use the application's session/connection management instead of creating a new connection. Thanks. On Wednesday, May 14, 2014 1:01:21 AM UTC+10, Michael Bayer wrote: > > if possible, I’d modify env.py to make use of your application’s normal > engine/session mechanics. There would be no “alembic_get_session()” > method. Whatever mechanism your app uses to get at the Engine/Session, > pull it in within env.py and use the exact same environment for migrations. > > > > > > On May 13, 2014, at 8:41 AM, gbr <doub...@directbox.com <javascript:>> > wrote: > > In some Alembic upgrade scripts, I need to use application sessions to > make use of some code that requires these sessions. To avoid deadlocks from > blocking transactions I use the following lines to transparently call > `get_db_session()` regardless of whether Alembic or the application is > executed: > > > def _alembic_get_db_session(): > from alembic import op > alembic_connection = op.get_bind() > return Session(bind=alembic_connection) > > > def _normal_get_db_session(): > return scoped_session(session_maker) > > > def get_db_session(): > if is_alembic_active: > return _alembic_get_db_session() > else: > return _normal_get_db_session() > > > How can I fill out the `is_alembic_active` part? I know that the > application is running and op.get_bind() is called, the following exception > is raised (I tried to check with op.get_bind() is None which obviously > doesn't work). > > NameError: Can't invoke function 'get_bind', as the proxy object has not >> yet been established for the Alembic 'Operations' class. Try placing this >> code inside a callable. >> > > Any idea? > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy-alembic" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy-alembic+unsubscr...@googlegroups.com <javascript:>. > For more options, visit https://groups.google.com/d/optout. > > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.