alembic check fails when not generating empty migration scripts #1332
-
Hi, I'm trying to re-add skipping of empty migrations to our def process_revision_directives(
context: MigrationContext,
revision: tuple[str, str],
directives: list[MigrationScript],
):
assert config.cmd_opts is not None
if config.cmd_opts.autogenerate:
script = directives[0]
assert script.upgrade_ops is not None
if script.upgrade_ops.is_empty():
directives[:] = [] with that, However, Here's the stacktrace
In the past, we did that with a rewriter, writer = rewriter.Rewriter()
@writer.rewrites(ops.MigrationScript)
def suppress_empty_migration_script(
context: MigrationContext, revision: tuple[str], op: ops.MigrationScript
) -> ops.MigrationScript:
"""If there is nothing to do, do NOT create an (empty) migration script, see
https://alembic.sqlalchemy.org/en/latest/cookbook.html#cookbook-no-empty-migrations.
"""
if op.upgrade_ops.is_empty():
op = []
return op but that also fails nowadays, with Here's the stacktrace
Is this a bug in alembic, or is this a bug in the proposed snippet? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi,
the issue seems to be in the snippet. If that work we can update the snippet |
Beta Was this translation helpful? Give feedback.
-
that would be great |
Beta Was this translation helpful? Give feedback.
Hi,
the issue seems to be in the snippet.
try using
if getattr(config.cmd_opts, 'autogenerate', False):
.If that work we can update the snippet