Skip to content

Consider Removing psql type specifiers when Comparing Computed Constructs #1462

Description

@tcommandeur

Describe the bug
I am using a Computed column in a Postgresql database and created a migration. The next migration I create with automigration returns a warning: alembic\autogenerate\compare.py:1034: UserWarning: Computed default on table.search_vector cannot be modified

The string generated for comparison by _normalize_computed_default:
setweightto_tsvectorenglish,title,a
setweightto_tsvectorenglish::regconfig,title::text,a::char

The code responsible for this:

def _normalize_computed_default(sqltext: str) -> str:
"""we want to warn if a computed sql expression has changed. however
we don't want false positives and the warning is not that critical.
so filter out most forms of variability from the SQL text.
"""
return re.sub(r"[ \(\)'\"`\[\]\t\r\n]", "", sqltext).lower()

Proposed solution
Remove groups of text starting with :: by adding another regex substitution.

 def _normalize_computed_default(sqltext: str) -> str: 
     """we want to warn if a computed sql expression has changed.  however 
     we don't want false positives and the warning is not that critical. 
     so filter out most forms of variability from the SQL text. 
     """ 
  
    normalized_sqltext = re.sub(r"[ \(\)'\"`\[\]]", "", sqltext).lower()
    return re.sub(r"::\w+", "", normalized_sqltext)

No activity

Activity on this issue will appear here.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcode review in progresscode has been provided that's in review as PR and/or gerritpostgresql

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions