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

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

Comments

@sqlalchemy-bot
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/__init__.py", line 148, in main_cli
    args.func(args)
  File "/home/breton/src/mediagoblin/mediagoblin/gmg_commands/dbupdate.py", line 234, in dbupdate
    run_dbupdate(app_config, global_config)
  File "/home/breton/src/mediagoblin/mediagoblin/gmg_commands/dbupdate.py", line 165, in run_dbupdate
    run_alembic_migrations(db, app_config, global_config)
  File "/home/breton/src/mediagoblin/mediagoblin/gmg_commands/dbupdate.py", line 136, in run_alembic_migrations
    return command.upgrade(cfg, 'heads')
  File "/home/breton/src/mediagoblin/local/lib/python2.7/site-packages/alembic/command.py", line 254, in upgrade
    script.run_env()
  File "/home/breton/src/mediagoblin/local/lib/python2.7/site-packages/alembic/script/base.py", line 416, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/home/breton/src/mediagoblin/local/lib/python2.7/site-packages/alembic/util/pyfiles.py", 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/compat.py", line 75, in load_module_py
    mod = imp.load_source(module_id, path, fp)
  File "/home/breton/src/mediagoblin/mediagoblin/db/migrations/env.py", line 63, in <module>
    run_migrations_online()
  File "/home/breton/src/mediagoblin/mediagoblin/db/migrations/env.py", line 58, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/home/breton/src/mediagoblin/local/lib/python2.7/site-packages/alembic/runtime/environment.py", line 817, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/home/breton/src/mediagoblin/local/lib/python2.7/site-packages/alembic/runtime/migration.py", line 330, in run_migrations
    self.connection.in_transaction():
AttributeError: 'Engine' object has no attribute 'in_transaction'

http://git.savannah.gnu.org/cgit/mediagoblin.git/tree/mediagoblin/db/migrations/env.py#n44 -- code that fails.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

hi there -

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

connection = config.attributes["session"].connection()
context.configure(
            connection=connection,
            target_metadata=target_metadata
            )

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".

@sqlalchemy-bot
Copy link
Author

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.

@sqlalchemy-bot
Copy link
Author

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
:class:~sqlalchemy.engine.Connection.

Change-Id: I95ef38955c00511d3055362a03284fb91677595f
Fixes: #419

adf0a7d

@sqlalchemy-bot
Copy link
Author

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
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant