fix broken migration when db is empty #21

Merged
kparal merged 1 commit from fix/alembic_events into develop 2021-03-23 14:17:34 +00:00
Contributor

Without any database sh init_db.sh crashes with an traceback:

INFO  [alembic.runtime.migration] Running upgrade 1e0fb82777af -> 31a71e8c7dfa, Event Dates
Traceback (most recent call last):
  File "/home/lbrabec/Playground/testdays-web/run_cli.py", line 26, in <module>
    exit = cli.main()
  File "/home/lbrabec/Playground/testdays-web/testdays/cli.py", line 125, in main
    command(options.destructive)
  File "/home/lbrabec/Playground/testdays-web/testdays/cli.py", line 78, in initialize_db
    upgrade_db()
  File "/home/lbrabec/Playground/testdays-web/testdays/cli.py", line 48, in upgrade_db
    al_command.upgrade(alembic_cfg, "head")
  File "/usr/lib/python3.9/site-packages/alembic/command.py", line 298, in upgrade
    script.run_env()
  File "/usr/lib/python3.9/site-packages/alembic/script/base.py", line 489, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/usr/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 98, in load_python_file
    module = load_module_py(module_id, path)
  File "/usr/lib/python3.9/site-packages/alembic/util/compat.py", line 184, in load_module_py
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "alembic/env.py", line 78, in <module>
    run_migrations_online()
  File "alembic/env.py", line 71, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/usr/lib/python3.9/site-packages/alembic/runtime/environment.py", line 846, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/usr/lib/python3.9/site-packages/alembic/runtime/migration.py", line 542, in run_migrations
    raise util.CommandError(
alembic.util.exc.CommandError: Migration "upgrade 1e0fb82777af -> 31a71e8c7dfa, Event Dates" has left an uncommitted transaction opened; transactional_ddl is False so Alembic is not committing transactions
Without any database `sh init_db.sh` crashes with an traceback: ``` INFO [alembic.runtime.migration] Running upgrade 1e0fb82777af -> 31a71e8c7dfa, Event Dates Traceback (most recent call last): File "/home/lbrabec/Playground/testdays-web/run_cli.py", line 26, in <module> exit = cli.main() File "/home/lbrabec/Playground/testdays-web/testdays/cli.py", line 125, in main command(options.destructive) File "/home/lbrabec/Playground/testdays-web/testdays/cli.py", line 78, in initialize_db upgrade_db() File "/home/lbrabec/Playground/testdays-web/testdays/cli.py", line 48, in upgrade_db al_command.upgrade(alembic_cfg, "head") File "/usr/lib/python3.9/site-packages/alembic/command.py", line 298, in upgrade script.run_env() File "/usr/lib/python3.9/site-packages/alembic/script/base.py", line 489, in run_env util.load_python_file(self.dir, "env.py") File "/usr/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 98, in load_python_file module = load_module_py(module_id, path) File "/usr/lib/python3.9/site-packages/alembic/util/compat.py", line 184, in load_module_py spec.loader.exec_module(module) File "<frozen importlib._bootstrap_external>", line 790, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "alembic/env.py", line 78, in <module> run_migrations_online() File "alembic/env.py", line 71, in run_migrations_online context.run_migrations() File "<string>", line 8, in run_migrations File "/usr/lib/python3.9/site-packages/alembic/runtime/environment.py", line 846, in run_migrations self.get_context().run_migrations(**kw) File "/usr/lib/python3.9/site-packages/alembic/runtime/migration.py", line 542, in run_migrations raise util.CommandError( alembic.util.exc.CommandError: Migration "upgrade 1e0fb82777af -> 31a71e8c7dfa, Event Dates" has left an uncommitted transaction opened; transactional_ddl is False so Alembic is not committing transactions ```
Contributor

👍

I'd like to see this code revisited, the "commit on every change" approach is IMO not ideal e.g. because it can leave the db in an inconsistent state (not that it would be such a big deal with this particular upgrade script). But for now, let's hotfix the breakage

:thumbsup: I'd like to see this code revisited, the "commit on every change" approach is IMO not ideal e.g. because it can leave the db in an inconsistent state (not that it would be such a big deal with this particular upgrade script). But for now, let's hotfix the breakage
Contributor

lgtm, thanks!

lgtm, thanks!
Contributor

Pull-Request has been merged by frantisekz

Pull-Request has been merged by frantisekz
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
quality/testdays-web!21
No description provided.