Skip to content
New issue

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

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

Already on GitHub? # to your account

Migration 8e3417e3713b_back_fill_the_token_user_id_column.py fails with AttributeError: 'Token' object has no attribute 'userid'. Did you mean: 'user_id' #8541

Closed
acelaya opened this issue Feb 20, 2024 · 0 comments · Fixed by #8546
Assignees
Labels

Comments

@acelaya
Copy link
Contributor

acelaya commented Feb 20, 2024

We have faced an issue in a dev environment which was several migrations behind. When trying to run the migrations via make db, we found that one failed, because it was depending on a model that changed since the migration was created.

This is the error it produced:

2024-02-20 09:53:41 57786 alembic.runtime.migration [INFO] Running upgrade 8fcdcefd8c6f -> 8e3417e3713b, Back-fill the token.user_id column.
Traceback (most recent call last):
  File "/home/alejandro/Development/hypothesis/h/.tox/dev/bin/alembic", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/alejandro/Development/hypothesis/h/.tox/dev/lib/python3.11/site-packages/alembic/config.py", line 641, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/home/alejandro/Development/hypothesis/h/.tox/dev/lib/python3.11/site-packages/alembic/config.py", line 631, in main
    self.run_cmd(cfg, options)
  File "/home/alejandro/Development/hypothesis/h/.tox/dev/lib/python3.11/site-packages/alembic/config.py", line 608, in run_cmd
    fn(
  File "/home/alejandro/Development/hypothesis/h/.tox/dev/lib/python3.11/site-packages/alembic/command.py", line 403, in upgrade
    script.run_env()
  File "/home/alejandro/Development/hypothesis/h/.tox/dev/lib/python3.11/site-packages/alembic/script/base.py", line 583, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/home/alejandro/Development/hypothesis/h/.tox/dev/lib/python3.11/site-packages/alembic/util/pyfiles.py", line 95, in load_python_file
    module = load_module_py(module_id, path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alejandro/Development/hypothesis/h/.tox/dev/lib/python3.11/site-packages/alembic/util/pyfiles.py", line 113, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/alejandro/Development/hypothesis/h/h/migrations/env.py", line 87, in <module>
    run_migrations_online()
  File "/home/alejandro/Development/hypothesis/h/h/migrations/env.py", line 77, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/home/alejandro/Development/hypothesis/h/.tox/dev/lib/python3.11/site-packages/alembic/runtime/environment.py", line 948, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/home/alejandro/Development/hypothesis/h/.tox/dev/lib/python3.11/site-packages/alembic/runtime/migration.py", line 627, in run_migrations
    step.migration_fn(**kw)
  File "/home/alejandro/Development/hypothesis/h/h/migrations/versions/8e3417e3713b_back_fill_the_token_user_id_column.py", line 31, in upgrade
    username, authority = split_userid(token.userid)
                                       ^^^^^^^^^^^^
AttributeError: 'Token' object has no attribute 'userid'. Did you mean: 'user_id'?

Let's update this migration to make sure it does not use business domain code.

@acelaya acelaya added the bug label Feb 20, 2024
@robertknight robertknight self-assigned this Feb 22, 2024
robertknight added a commit that referenced this issue Feb 22, 2024
Replace imports from `h.models` with local ORM classes. The ORM classes in
`h.models` assume the DB has the latest schema, which is not the case when
running migrations. The new code matches how other migrations work.

Fixes #8541
robertknight added a commit that referenced this issue Feb 22, 2024
Replace imports from `h.models` with local ORM classes. The ORM classes in
`h.models` assume the DB has the latest schema, which is not the case when
running migrations. The new code matches how other migrations work.

Fixes #8541
robertknight added a commit that referenced this issue Feb 23, 2024
Replace imports from `h.models` with local ORM classes. The ORM classes in
`h.models` assume the DB has the latest schema, which is not the case when
running migrations. The new code matches how other migrations work.

Fixes #8541
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants