Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'Engine' object has no attribute 'in_transaction' #419

sqlalchemy-bot opened this issue Mar 3, 2017 · 4 comments
bug Something isn't working


Copy link

Migrated issue, originally created by bretonium (@bretonium)

Release 0.9.x broke our migrations, they now fail with traceback:

breton@breton-pc ~/src/mediagoblin (master*) $ ./bin/gmg dbupdate            
WARNING: audiolab is not installed so wav2png will not work
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> 52bf0ccbedc1, initial revision
Traceback (most recent call last):
  File "./bin/gmg", line 11, in <module>
    load_entry_point('mediagoblin', 'console_scripts', 'gmg')()
  File "/home/breton/src/mediagoblin/mediagoblin/gmg_commands/", line 148, in main_cli
  File "/home/breton/src/mediagoblin/mediagoblin/gmg_commands/", line 234, in dbupdate
    run_dbupdate(app_config, global_config)
  File "/home/breton/src/mediagoblin/mediagoblin/gmg_commands/", line 165, in run_dbupdate
    run_alembic_migrations(db, app_config, global_config)
  File "/home/breton/src/mediagoblin/mediagoblin/gmg_commands/", line 136, in run_alembic_migrations
    return command.upgrade(cfg, 'heads')
  File "/home/breton/src/mediagoblin/local/lib/python2.7/site-packages/alembic/", line 254, in upgrade
  File "/home/breton/src/mediagoblin/local/lib/python2.7/site-packages/alembic/script/", line 416, in run_env
    util.load_python_file(self.dir, '')
  File "/home/breton/src/mediagoblin/local/lib/python2.7/site-packages/alembic/util/", line 93, in load_python_file
    module = load_module_py(module_id, path)
  File "/home/breton/src/mediagoblin/local/lib/python2.7/site-packages/alembic/util/", line 75, in load_module_py
    mod = imp.load_source(module_id, path, fp)
  File "/home/breton/src/mediagoblin/mediagoblin/db/migrations/", line 63, in <module>
  File "/home/breton/src/mediagoblin/mediagoblin/db/migrations/", line 58, in run_migrations_online
  File "<string>", line 8, in run_migrations
  File "/home/breton/src/mediagoblin/local/lib/python2.7/site-packages/alembic/runtime/", line 817, in run_migrations
  File "/home/breton/src/mediagoblin/local/lib/python2.7/site-packages/alembic/runtime/", line 330, in run_migrations
AttributeError: 'Engine' object has no attribute 'in_transaction' -- code that fails.

Copy link

Michael Bayer (@zzzeek) wrote:

hi there -

The "connection" parameter to EnvironmentContext.configure is documented as a Connection, not an Engine. Your needs to say:

connection = config.attributes["session"].connection()

otherwise if you're doing tranasctional DDL I think you're skipping outside of the transaction. It is a little bit of a bug that passing the Engine is otherwise "working".

Copy link

bretonium (@bretonium) wrote:

Thank you, switched to connection(), it works.

I am not sure what to do with the bugreport, so please close it if you feel that it's not really a bug.

Copy link

Michael Bayer (@zzzeek) wrote:

Warn on non-Connection present and accommodate for Engine

A warning is emitted when an object that's not a
:class:~sqlalchemy.engine.Connection is passed to
:meth:.EnvironmentContext.configure. For the case of a
:class:~sqlalchemy.engine.Engine passed, the check for "in transaction"
introduced in version 0.9.0 has been relaxed to work in the case of an
attribute error, as some users appear to be passing an
:class:~sqlalchemy.engine.Engine and not a

Change-Id: I95ef38955c00511d3055362a03284fb91677595f
Fixes: #419


Copy link

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added the bug Something isn't working label Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
bug Something isn't working
None yet

No branches or pull requests

1 participant