def save(self, session=None): """Save this object.""" if not session: session = sa.get_session() # NOTE(boris-42): This part of code should be look like: # sesssion.add(self) # session.flush() # But there is a bug in sqlalchemy and eventlet that # raises NoneType exception if there is no running # transaction and rollback is called. As long as # sqlalchemy has this bug we have to create transaction # explicity. with session.begin(subtransactions=True): session.add(self) session.flush()
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 = sa_session.get_session().get_bind() #engine = engine_from_config( # config.get_section(config.config_ini_section), # prefix='sqlalchemy.', # poolclass=pool.NullPool) connection = engine.connect() context.configure( connection=connection, target_metadata=target_metadata ) try: with context.begin_transaction(): context.run_migrations() finally: connection.close()
def get_session(): return db_session.get_session()