Skip to content

Commit

Permalink
Ignore mypy errors for migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrovRoman committed Aug 19, 2024
1 parent 4ecc17f commit ff52cd4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions alembic_postgresql_enum/operations/sync_enum_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ def is_column_type_import_needed(self) -> bool:
@alembic.autogenerate.render.renderers.dispatch_for(SyncEnumValuesOp)
def render_sync_enum_value_op(autogen_context: AutogenContext, op: SyncEnumValuesOp):
if op.is_column_type_import_needed:
autogen_context.imports.add("from alembic_postgresql_enum import ColumnType")
autogen_context.imports.add("from alembic_postgresql_enum import TableReference")
autogen_context.imports.add("from alembic_postgresql_enum import ColumnType # type: ignore[attr-defined]")
autogen_context.imports.add("from alembic_postgresql_enum import TableReference # type: ignore[attr-defined]")

return (
f"op.sync_enum_values({op.schema!r}, {op.name!r}, {op.new_values!r},\n"
f"op.sync_enum_values({op.schema!r}, {op.name!r}, {op.new_values!r},\n # type: ignore[attr-defined]"
f" {op.affected_columns!r},\n"
f" enum_values_to_rename=[])"
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "alembic-postgresql-enum"
version = "1.3.0"
version = "1.3.1"
description = "Alembic autogenerate support for creation, alteration and deletion of enums"
authors = ["RustyGuard"]
license = "MIT"
Expand Down
7 changes: 4 additions & 3 deletions tests/sync_enum_values/test_array_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,22 @@ def test_add_new_enum_value_render_with_array(connection: "Connection"):
autogenerate._render_migration_diffs(context, template_args)

assert template_args["imports"] == (
"from alembic_postgresql_enum import ColumnType" "\nfrom alembic_postgresql_enum import TableReference"
"from alembic_postgresql_enum import ColumnType # type: ignore[attr-defined]"
"\nfrom alembic_postgresql_enum import TableReference # type: ignore[attr-defined]"
)

assert (
template_args["upgrades"]
== f"""# ### commands auto generated by Alembic - please adjust! ###
op.sync_enum_values('{DEFAULT_SCHEMA}', '{CAR_COLORS_ENUM_NAME}', [{', '.join(map(repr, new_enum_variants))}],
op.sync_enum_values('{DEFAULT_SCHEMA}', '{CAR_COLORS_ENUM_NAME}', [{', '.join(map(repr, new_enum_variants))}], # type: ignore[attr-defined]
[TableReference(table_schema='{DEFAULT_SCHEMA}', table_name='{CAR_TABLE_NAME}', column_name='{CAR_COLORS_COLUMN_NAME}', column_type=ColumnType.ARRAY)],
enum_values_to_rename=[])
# ### end Alembic commands ###"""
)
assert (
template_args["downgrades"]
== f"""# ### commands auto generated by Alembic - please adjust! ###
op.sync_enum_values('{DEFAULT_SCHEMA}', '{CAR_COLORS_ENUM_NAME}', [{', '.join(map(repr, old_enum_variants))}],
op.sync_enum_values('{DEFAULT_SCHEMA}', '{CAR_COLORS_ENUM_NAME}', [{', '.join(map(repr, old_enum_variants))}], # type: ignore[attr-defined]
[TableReference(table_schema='{DEFAULT_SCHEMA}', table_name='{CAR_TABLE_NAME}', column_name='{CAR_COLORS_COLUMN_NAME}', column_type=ColumnType.ARRAY)],
enum_values_to_rename=[])
# ### end Alembic commands ###"""
Expand Down
8 changes: 4 additions & 4 deletions tests/sync_enum_values/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def test_add_new_enum_value_render(connection: "Connection"):
assert (
template_args["upgrades"]
== f"""# ### commands auto generated by Alembic - please adjust! ###
op.sync_enum_values('{DEFAULT_SCHEMA}', '{USER_STATUS_ENUM_NAME}', [{', '.join(map(repr, new_enum_variants))}],
op.sync_enum_values('{DEFAULT_SCHEMA}', '{USER_STATUS_ENUM_NAME}', [{', '.join(map(repr, new_enum_variants))}], # type: ignore[attr-defined]
[TableReference(table_schema='{DEFAULT_SCHEMA}', table_name='{USER_TABLE_NAME}', column_name='{USER_STATUS_COLUMN_NAME}')],
enum_values_to_rename=[])
# ### end Alembic commands ###"""
)
assert (
template_args["downgrades"]
== f"""# ### commands auto generated by Alembic - please adjust! ###
op.sync_enum_values('{DEFAULT_SCHEMA}', '{USER_STATUS_ENUM_NAME}', [{', '.join(map(repr, old_enum_variants))}],
op.sync_enum_values('{DEFAULT_SCHEMA}', '{USER_STATUS_ENUM_NAME}', [{', '.join(map(repr, old_enum_variants))}], # type: ignore[attr-defined]
[TableReference(table_schema='{DEFAULT_SCHEMA}', table_name='{USER_TABLE_NAME}', column_name='{USER_STATUS_COLUMN_NAME}')],
enum_values_to_rename=[])
# ### end Alembic commands ###"""
Expand Down Expand Up @@ -207,7 +207,7 @@ class ExampleTable(Base):
def get_expected_upgrade(self) -> str:
return """
# ### commands auto generated by Alembic - please adjust! ###
op.sync_enum_values('public', 'my_enum', ['one', 'two', 'three', 'four'],
op.sync_enum_values('public', 'my_enum', ['one', 'two', 'three', 'four'], # type: ignore[attr-defined]
[TableReference(table_schema='public', table_name='example_table', column_name='enum_field', existing_server_default="'one'::my_enum")],
enum_values_to_rename=[])
# ### end Alembic commands ###
Expand All @@ -216,7 +216,7 @@ def get_expected_upgrade(self) -> str:
def get_expected_downgrade(self) -> str:
return """
# ### commands auto generated by Alembic - please adjust! ###
op.sync_enum_values('public', 'my_enum', ['one', 'two', 'three'],
op.sync_enum_values('public', 'my_enum', ['one', 'two', 'three'], # type: ignore[attr-defined]
[TableReference(table_schema='public', table_name='example_table', column_name='enum_field', existing_server_default="'one'::my_enum")],
enum_values_to_rename=[])
# ### end Alembic commands ###
Expand Down
4 changes: 2 additions & 2 deletions tests/sync_enum_values/test_run_array_new_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_expected_upgrade(self) -> str:
return """
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('a', sa.Column('value', postgresql.ARRAY(postgresql.ENUM('A', 'B', 'C', name='my_enum', create_type=False)), server_default=sa.text("ARRAY['A', 'B']::my_enum[]"), nullable=True))
op.sync_enum_values('public', 'my_enum', ['A', 'B', 'C'],
op.sync_enum_values('public', 'my_enum', ['A', 'B', 'C'], # type: ignore[attr-defined]
[TableReference(table_schema='public', table_name='a', column_name='value', column_type=ColumnType.ARRAY, existing_server_default="ARRAY['A', 'B']::my_enum[]"), TableReference(table_schema='public', table_name='b', column_name='value', column_type=ColumnType.ARRAY, existing_server_default="ARRAY['A'::my_enum, 'B'::my_enum]")],
enum_values_to_rename=[])
# ### end Alembic commands ###
Expand All @@ -72,7 +72,7 @@ def get_expected_upgrade(self) -> str:
def get_expected_downgrade(self) -> str:
return """
# ### commands auto generated by Alembic - please adjust! ###
op.sync_enum_values('public', 'my_enum', ['A', 'B'],
op.sync_enum_values('public', 'my_enum', ['A', 'B'], # type: ignore[attr-defined]
[TableReference(table_schema='public', table_name='a', column_name='value', column_type=ColumnType.ARRAY, existing_server_default="ARRAY['A', 'B']::my_enum[]"), TableReference(table_schema='public', table_name='b', column_name='value', column_type=ColumnType.ARRAY, existing_server_default="ARRAY['A'::my_enum, 'B'::my_enum]")],
enum_values_to_rename=[])
op.drop_column('a', 'value')
Expand Down

0 comments on commit ff52cd4

Please sign in to comment.