Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider Removing psql type specifiers when Comparing Computed Constructs #1462

Open
tcommandeur opened this issue Apr 23, 2024 · 1 comment
Labels
bug Something isn't working postgresql

Comments

@tcommandeur
Copy link

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)
@tcommandeur tcommandeur added the requires triage New issue that requires categorization label Apr 23, 2024
@CaselIT
Copy link
Member

CaselIT commented May 31, 2024

Hi,

seems like a sensible solution. There is already some code that's trying to compare the index expression in the postgresql dialect, so maybe that could be re-used.

Could you provided a PR for it?

@CaselIT CaselIT added bug Something isn't working postgresql and removed requires triage New issue that requires categorization labels May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working postgresql
Projects
None yet
Development

No branches or pull requests

2 participants