sqlalchemy / sqlalchemy/alembic
Consider Removing psql type specifiers when Comparing Computed Constructs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 375
- PR merge metrics
- No merged PRs in 30d
Description
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:
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in alembic/autogenerate/compare.py at _normalize_computed_default, which currently normalizes computed SQL text before comparison. Verify the PostgreSQL example, update the normalization so :: type specifiers are ignored, and confirm that equivalent computed expressions no longer produce the modification warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100