Repository navigation
fix(sql): preserve comma joins and dblink suffixes in routine bodies (#5169) - #5173
mohitdixit02 wants to merge 1 commit into
Conversation
|
Thanks for the pull request, @mohitdixit02. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 4 changed function(s) (4 sampled, not proven).
Formal verification. PR-changed functions: 4/4 verified (0 proven, 4 may-equivalent, 0 distinguished) · 0 not verified.
Graphify review — findings
Adds comma-join and @dblink support to SQL routine-body extraction, so FROM hr.emp a, hr.dept d now yields a reads_from edge for every table instead of only the first. Remote references like hr.emp@remote_db keep their link suffix on read and write targets, and they stay distinct nodes from the local hr.emp. The @ handling in _clean_ident and _norm_ident splits on the first @ without regard to quoting, so a quoted or bracketed name that contains @ can get a garbled label or a mismatched lookup key.
Worth a look
- _norm_ident splits on '@' inside quoted/bracketed parts, breaking lookup key equivalence —
graphify/extractors/sql.py:464· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
- _clean_ident splits on '@' inside bracketed/quoted identifiers, garbling labels —
graphify/extractors/sql.py:443· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3176 functions depend on the 47 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract_sql()— 47 callers, 13 callees
Verification — 3176 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: 1229 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
7 of 560 test file(s) selected (1%) via static blast radius.
tests/test_extract.py— impacttests/test_multilang.py— impacttests/test_pg_introspect.py— impacttests/test_python_member_call_language_gate.py— impacttests/test_sql_comma_joins_and_dblink.py— impact, changed-testtests/test_sql_go_batches.py— impacttests/test_sql_tsql_procedures.py— impact
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
No difference found (not proven): No behavior difference found in \_clean\_ident (not a proof).
The verifier ran both versions of \_clean\_ident on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
No difference found (not proven): No behavior difference found in \_norm\_ident (not a proof).
The verifier ran both versions of \_norm\_ident on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
No difference found (not proven): No behavior difference found in \_routine\_body\_refs (not a proof).
The verifier ran both versions of \_routine\_body\_refs on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
No difference found (not proven): No behavior difference found in extract\_sql (not a proof).
The verifier ran both versions of extract\_sql on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
· 1 more finding(s) on lines outside this diff (see the check run).
|
Landed on v8 as e605f4a via authorship-preserving cherry-pick, released in graphify 0.9.108. Thanks @mohitdixit02. |
What does this PR do?
Fixes #5169.
In
graphify/extractors/sql.py, SQL routine body scanning suffered from two reference extraction gaps:_BODY_READ_RXonly matched table identifiers immediately preceded byFROMorJOIN. In classic multi-table comma joins (FROM hr.emp a, hr.dept d), any table following a comma was missed, losingreads_fromedges for all tables after the first._BODY_TAIL = r"(?![\w$]|\s*\.)"permitted@immediately after table identifiers. When readingFROM hr.emp@remote_dbor writing toINSERT INTO hr.emp_copy@remote_db, the regex matched up to@and silently stripped the@dblinksuffix, falsely linking the reference to a local table of the same name.This change:
,\s*<ident>[\s+alias]) following aFROMclause in_routine_body_refs, stopping at SQL keywords (WHERE,GROUP BY,ORDER BY) and parenthesized function calls.@in_BODY_TAIL((?![\w$@]|\s*\.)) and incorporates optional@dblinksuffix matching in_BODY_TABLE_IDENT,_clean_ident,_norm_ident, and the AST_walk_from_refspath. Remote tables are uniquely preserved and keyed as distinct nodes.Type of change
Verification & Invariants
How was this tested?
uv run pytest tests/test_sql_tsql_procedures.py tests/test_sql_go_batches.py tests/test_sql_cross_file_tables.py tests/test_sql_comma_joins_and_dblink.py -v uv run ruff check graphify/extractors/sql.py tests/test_sql_comma_joins_and_dblink.py uv run python -m graphify update .Graphify-specific checklist