Skip to content

Add regression test for T-SQL bracketed FK dropping child table - #2722

Open
ayushcodes10 wants to merge 2 commits into
Graphify-Labs:v8from
ayushcodes10:fix-2713-tsql-fk-self-loop
Open

Add regression test for T-SQL bracketed FK dropping child table#2722
ayushcodes10 wants to merge 2 commits into
Graphify-Labs:v8from
ayushcodes10:fix-2713-tsql-fk-self-loop

Conversation

@ayushcodes10

@ayushcodes10 ayushcodes10 commented Aug 13, 2026

Copy link
Copy Markdown

A bracket-quoted FOREIGN KEY ... REFERENCES clause could confuse the
parser badly enough that the whole child table (with its FK
constraint) landed as bogus nested content inside the parent table's
own subtree, dropping the child table from the graph and fabricating
a self-referencing EXTRACTED edge on the parent. Already fixed as a
side effect of the #2712 debracketing change; this adds coverage for
the specific #2713 repro.

Fixes #2713.

tree-sitter-sql has no grammar token for T-SQL [bracket] quoting: each
bracket lands as its own ERROR node, one byte short of the real pair,
so [dbo].[Alpha] reads back as the label `dbo].[Alpha` instead of
dbo.Alpha. Rewrite bracket-quoted identifiers to backtick-quoted ones
before parsing (a form the grammar already handles cleanly), then
strip the synthetic backticks back out for display. Guards against
misfiring on Postgres/MySQL array-type syntax (text[], numeric(10)[3]).

Fixes Graphify-Labs#2712.
A bracket-quoted FOREIGN KEY ... REFERENCES clause could confuse the
parser badly enough that the whole child table (with its FK
constraint) landed as bogus nested content inside the parent table's
own subtree, dropping the child table from the graph and fabricating
a self-referencing EXTRACTED edge on the parent. Already fixed as a
side effect of the Graphify-Labs#2712 debracketing change on this branch; this adds
coverage for the specific Graphify-Labs#2713 repro.

Fixes Graphify-Labs#2713.

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

This pull request adds T-SQL bracket-quoted identifier support to the SQL extractor. It introduces two helper functions (_debracket_tsql, which rewrites [bracket]-quoted identifiers to backtick-quoted ones before parsing to work around a tree-sitter-sql grammar gap, and _strip_backtick_parts, which undoes that substitution for display labels), and wires them into extract_sql via new _clean_name and _ident helpers applied wherever identifier/object_reference nodes are read. The change is gated so debracketing is skipped when source already contains a backtick, and includes handling for string literals, comments, and array-type syntax. The test file adds new cases covering bracket identifier labeling, cross-reference resolution, array-type non-corruption, and other scenarios; the accompanying symbol churn in the test module reflects these additions.

No blocking issues surfaced. 5 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 271 functions depend on the 117 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract_sql() — 13 callers, 9 callees
  • worse: walk() — 1 callers, 9 callees

Verification — 271 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 128 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify extract\_sql.

The verifier did not have enough to check extract\_sql, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

· 1 grounded finding(s) anchored inline below; 1 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/extractors/sql.py
@ayushcodes10 ayushcodes10 changed the title Fix 2713 tsql fk self loop Add regression test for T-SQL bracketed FK dropping child table Aug 13, 2026
@ayushcodes10

Copy link
Copy Markdown
Author

@safishamsi this PR's CI run is waiting on approval (first-time contributor gate) — could you approve the workflow run when you get a chance? Happy to address any review feedback in the meantime.

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.

T-SQL: a bracketed FOREIGN KEY can drop the child table entirely and emit a self-referencing edge tagged EXTRACTED

1 participant