Fix: preserve quoted_name(quote=...) semantics when rendering schema in autogenerate - #1843
Open
pranjalm37 wants to merge 1 commit into
Open
Fix: preserve quoted_name(quote=...) semantics when rendering schema in autogenerate#1843pranjalm37 wants to merge 1 commit into
pranjalm37 wants to merge 1 commit into
Conversation
…in autogenerate When a table's schema is set using an explicit quoted_name(name, quote=True/False), the autogenerate render code collapsed it down to a plain string literal, silently dropping the caller's explicit quoting preference in the generated migration file. Adds _render_schema_ident() which preserves the quoted_name(...) wrapper when quote is explicitly set, and otherwise preserves prior behavior (including support for custom repr()-able schema objects). Applied consistently across all schema= render sites: create/drop table, index, column, constraints, and the batch_alter_table header. Fixes sqlalchemy#1526
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1526.
When a table/index/constraint's schema is set using an explicit
quoted_name(name, quote=True)orquoted_name(name, quote=False), theautogenerate render code (
_ident()inalembic/autogenerate/render.py)collapsed the value down to a plain string before formatting it with
%r,so the caller's explicit quoting preference was silently dropped from the
generated migration file.
Fix
Adds
_render_schema_ident(), used at everyschema=render site(create/drop table, index, column, check/unique constraint, drop_constraint,
alter_column, and the
batch_alter_tableheader):quoted_namewithquoteexplicitly set (True/False),render it as
quoted_name('name', True/False)and add the necessary importto the generated migration file.
repr()of the original value, preserving priorbehavior — including for objects with a custom
__repr__(there's anexisting test,
test_drop_unique_constraint_schema_reprobj, covering thatcase, which still passes).
Test plan
test_render_table_w_quoted_name_schema, matching the repro fromMigration autogeneration should respect schemas defined using quoted_name #1526, asserting both the rendered code and that the
quoted_nameimportis added.
pytest tests/ --ignore=tests/test_post_write.py --ignore=tests/test_mssql.py --ignore=tests/test_oracle.py --ignore=tests/test_mysql.py --ignore=tests/test_postgresql.py→ 1562 passed, 133 skipped (DB-specific suites skipped, no local DB available;test_post_write.pyfailures are pre-existing/unrelated — they fail identically onmainwithout this change, due toblacknot being installed in the hook environment).black --checkandflake8pass on both changed files.docs/build/unreleased/1526.rst.