alembic autogeneration "false-positively" detects change to comments from the empty string to None
Describe the bug
Setting column comment to "" causes autogenerate to create changes even though no changes were made.
Expected behavior
I expected Column("mycol", sa.types.String(), comment="") to be treated as it is, and that sequential autogenerate commands would generate empty migrations.
To Reproduce Please try to provide a Minimal, Complete, and Verifiable example, with the migration script and/or the SQLAlchemy tables or models involved. See also Reporting Bugs on the website.
-
Code:
class MyTable(Base): __tablename__ = "my_table" mycol = ColumnNonNull( sa.types.String(), primary_key=True, comment=""" """.strip(), ) -
Table generation ok as expected:
def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.create_table( "my_table", sa.Column("mycol", sa.String(), nullable=False), sa.PrimaryKeyConstraint("mycol"), schema="public", ) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_table("my_table", schema="public") # ### end Alembic commands ### -
Table generation not ok:
def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.alter_column( "my_table", "mycol", existing_type=sa.VARCHAR(), comment="", existing_nullable=False, ) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.alter_column( "my_table", "mycol", existing_type=sa.VARCHAR(), comment=None, existing_comment="", existing_nullable=False, ) # ### end Alembic commands ###-
Expected:
def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### pass # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### pass # ### end Alembic commands ###
-
Error
No errors per se.
Fix
If I set the column to anything other than "" it then starts to work as expected.
Versions.
- OS: Ubuntu 20.04.5 LTS
- Python: 3.8
- Alembic: alembic==1.8.1
- Database:
PostgreSQL
Hi,
this is probably because somewhere there is something like an if comment and somewhere else there is a if commnet is not None.
Thanks for reporting, but I'm not sure this warrants a fix, since the workaround is trivial