Autogenerates crashes because `metadata` is a list (`[Metadata()]`) instead of `Metadata()`
jsmits opened this issue · 1 comments
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
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.