Skip to content

Strip PostgreSQL type cast specifiers when comparing computed defaults#1826

Open
cycsmail wants to merge 1 commit into
sqlalchemy:mainfrom
cycsmail:strip-pg-type-casts-computed-default-1462
Open

Strip PostgreSQL type cast specifiers when comparing computed defaults#1826
cycsmail wants to merge 1 commit into
sqlalchemy:mainfrom
cycsmail:strip-pg-type-casts-computed-default-1462

Conversation

@cycsmail

@cycsmail cycsmail commented Jul 5, 2026

Copy link
Copy Markdown

Fixes: #1462. On PostgreSQL, reflected computed-column expressions come back with type cast specifiers (e.g. ::regconfig, ::text, ::char) that aren't present on the metadata side, causing autogenerate to raise a false-positive "Computed default ... cannot be modified" warning even when the expressions are equivalent.

Extends _normalize_computed_default() to strip those ::<type> specifiers after the existing whitespace/quote normalization, so the two sides compare equal. Added a unit test normalizing the cast-laden expression from the issue against the cast-free one (fails without the fix, confirmed via git stash), plus a changelog entry under docs/build/unreleased/.

tests/test_postgresql.py passes (70 passed) and ruff check is clean on the touched files.

Checklist

This pull request is:

  • A documentation / typographical error fix
  • A short code fix
  • A new feature implementation

Have a nice day!

@CaselIT CaselIT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposed change cannot be there since it postgresql specific.

Also in the postgresql impl there is already something similar implemented in _cleanup_index_expr that could be re-used for this

normalized_sqltext = re.sub(r"[ \(\)'\"`\[\]\t\r\n]", "", sqltext).lower()
# strip postgresql type cast specifiers, e.g. ``::regconfig``, ``::text``,
# which can appear inconsistently and cause false-positive warnings.
return re.sub(r"::\w+", "", normalized_sqltext)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can't be here since this is generic for all databases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider Removing psql type specifiers when Comparing Computed Constructs

2 participants