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

Autogenerates crashes because metadata is a list ([Metadata()]) instead of Metadata() #23

Closed
jsmits opened this issue Sep 9, 2023 · 1 comment · Fixed by #24
Closed
Assignees
Labels
bug Something isn't working

Comments

@jsmits
Copy link

jsmits commented Sep 9, 2023

I encountered the following after adding an Enum field to one of my models and trying to autogenerate the migration:

# added this field to my model (got the same error by using `Column` instead of `mapped_column`)
status: Mapped[ENUM] = mapped_column(
    ENUM("pending", "success", "error", name="status")
)
  File "~/.pyenv/versions/3.11.3/envs/backend/lib/python3.11/site-packages/alembic_postgresql_enum/compare_dispatch.py", line 32, in compare_enums
    declarations = get_declared_enums(autogen_context.metadata, schema, default_schema, autogen_context.dialect)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.pyenv/versions/3.11.3/envs/backend/lib/python3.11/site-packages/alembic_postgresql_enum/get_enum_data.py", line 127, in get_declared_enums
    for table in metadata.tables.values():
                 ^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'tables'

Turns out metadata is indeed a list, i.e. [Metadata()]. If I set a breakpoint in get_declared_enums(...) and add autogen_context.metadata = autogen_context.metadata[0] as the first line in that function, then everything works just fine. Then the migration is created correctly.

Could this be a bug or would it be more likely to be something wrong in my set up that causes this? No idea where to start looking if it's the latter though.

Versions used:

alembic==1.12.0
alembic-postgresql-enum==0.1.7
@jsmits
Copy link
Author

jsmits commented Sep 9, 2023

Found it (also to reproduce): my target_metadata in env.py is a list, something like target_metadata = [my_models.Base.metadata].

With target_metadata = my_models.Base.metadata the migration is created just fine. However, target_metadata is allowed to be a list from an alembic-perspective, afaik.

@RustyGuard RustyGuard added the bug Something isn't working label Sep 9, 2023
@RustyGuard RustyGuard self-assigned this Sep 9, 2023
@jsmits jsmits changed the title Autogenerates crashes because metadata is a list ([Metadata()]), Metadata() Autogenerates crashes because metadata is a list ([Metadata()]) instead of Metadata() Sep 9, 2023
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
2 participants