Skip to content

Recover bracket-quoted CREATE PROCEDURE/FUNCTION names - #2721

Open
ayushcodes10 wants to merge 3 commits into
Graphify-Labs:v8from
ayushcodes10:fix-2718-tsql-bracket-routines
Open

Recover bracket-quoted CREATE PROCEDURE/FUNCTION names#2721
ayushcodes10 wants to merge 3 commits into
Graphify-Labs:v8from
ayushcodes10:fix-2718-tsql-bracket-routines

Conversation

@ayushcodes10

@ayushcodes10 ayushcodes10 commented Aug 13, 2026

Copy link
Copy Markdown

This grammar has no rule at all for T-SQL's AS BEGIN...END routine
body, bracketed name or not, so every CREATE PROCEDURE/FUNCTION only
ever gets extracted through the ERROR-node regex fallback. That
fallback matched a bare or double-quoted name but not a bracket-quoted
one, so a bracketed routine name produced no node at all rather than a
mangled one (0 of 845 procedures on a real SSMS-scripted dump).
Extends the fallback's name pattern to also match a backtick-quoted
name, which recovers a bracketed T-SQL name once #2712's
debracketing has rewritten it.

Fixes #2718.

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.
This grammar has no rule at all for T-SQL's AS BEGIN...END routine
body, bracketed name or not, so every CREATE PROCEDURE/FUNCTION only
ever gets extracted through the ERROR-node regex fallback. That
fallback matched a bare or double-quoted name but not a bracket-quoted
one, so a bracketed routine name produced no node at all rather than a
mangled one (0 of 845 procedures on a real SSMS-scripted dump).
Extends the fallback's name pattern to also match a backtick-quoted
name, which recovers a bracketed T-SQL name once Graphify-Labs#2712's
debracketing has rewritten it.

Fixes Graphify-Labs#2718.

@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 PR adds T-SQL bracket-quoted identifier handling to the SQL extractor in graphify/extractors/sql.py. It introduces a _debracket_tsql preprocessing pass that rewrites [bracket]-quoted identifiers to backtick-quoted ones before parsing (guarded to skip files that already contain backticks), plus _strip_backtick_parts and helper functions (_clean_name, _ident) to strip the synthetic backticks back out when producing display names. It also factors out a shared _SQL_NAME_PART regex fragment used by the ERROR-node fallback paths and routes existing name-reading call sites through the new identifier helpers. The accompanying test file (tests/test_multilang.py) is updated with new and modified cases covering the bracket-debracketing behavior, array-type handling, and various existing multi-language extraction scenarios across SQL, Go, TypeScript, and Rust.

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

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 275 functions depend on the 121 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract_sql() — 15 callers, 10 callees
  • worse: walk() — 1 callers, 10 callees

Verification — 275 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: 132 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 2718 tsql bracket routines Recover bracket-quoted CREATE PROCEDURE/FUNCTION names 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 bracket-quoted CREATE PROCEDURE / CREATE FUNCTION name yields no node at all (0 of 845 procedures on a real dump)

1 participant