Skip to content

fix(parser): stop dropping columns named like constraint keywords - #39

Merged
Peter-L-SVK merged 1 commit into
Peter-L-SVK:stagefrom
Sal-ami:fix/schema-parser-constraint-keyword-columns
Oct 10, 2026
Merged

Peter-L-SVK merged 1 commit into
Peter-L-SVK:stagefrom
Sal-ami:fix/schema-parser-constraint-keyword-columns

Conversation

@Sal-ami

@Sal-ami Sal-ami commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

The constraint check in _parse_column_line_robust used str.startswith() against a tuple of keywords. startswith matches prefixes, so any column whose name merely began with one of the keywords got treated as a table constraint and dropped.

This table loses three columns silently:

CREATE TABLE t (
    id SERIAL PRIMARY KEY,
    unique_code VARCHAR(10),
    constraint_name VARCHAR(50),
    check_flag BOOLEAN
);

Parsing it returns only id. The Schema Designer draws the table with a third of its columns missing and shows no error, so it looks like the SQL only ever declared one column.

The keywords are now matched with a word boundary. PRIMARY KEY (a, b), UNIQUE (email) and CONSTRAINT chk_len CHECK (...) are still skipped, and prefixed column names parse as columns.

Two tests added:

  • one covers the column names above and fails on the current code with unique_code and constraint_name missing from the result
  • one pins down that table-level constraints are still skipped, so the fix cannot drift the other way

Verified locally with the four test files that do not need a live database:

pytest tests/test_schema_parser.py tests/test_schema_cache.py tests/test_settings.py tests/test_models.py
80 passed

black --check and flake8 are clean on both changed files. mypy reports no issues on schema_parser.py. I could not run the database backed tests because there is no PostgreSQL server on my machine at this time.

The constraint check in _parse_column_line_robust used
str.startswith() against a tuple of keywords. That matched any column
whose name merely began with one of them, so unique_code,
constraint_name, check_flag and excluded_at were all treated as table
constraints and silently dropped.

The Schema Designer then drew a table with fewer columns than the SQL
declares and gave no warning.

The keywords are now matched with a word boundary so PRIMARY KEY (a, b),
UNIQUE (email) and CONSTRAINT ... CHECK (...) are still skipped while
prefixed column names parse as columns.

Adds two tests. One fails on the old code with unique_code and
constraint_name missing from the column list. The other pins down that
table-level constraints are still skipped.
@Sal-ami

Sal-ami commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

no ai btw

@Peter-L-SVK Peter-L-SVK added bugfix enhancement New feature or request good first issue Good for newcomers labels Oct 10, 2026
@Peter-L-SVK
Peter-L-SVK merged commit a461cf9 into Peter-L-SVK:stage Oct 10, 2026
5 checks passed
@Sal-ami
Sal-ami deleted the fix/schema-parser-constraint-keyword-columns branch October 10, 2026 13:47
@Sal-ami
Sal-ami restored the fix/schema-parser-constraint-keyword-columns branch October 10, 2026 13:47
@Peter-L-SVK
Peter-L-SVK self-requested a review October 10, 2026 15:19
@Peter-L-SVK Peter-L-SVK self-assigned this Oct 10, 2026
@Peter-L-SVK
Peter-L-SVK removed their request for review October 10, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix enhancement New feature or request good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants