Skip to content

SQL: partially parsed procedure headers produce duplicate and malformed routine nodes with tree-sitter-sql 0.3.13 #5236

Closed

Description

@sub4biz

Summary

With graphify v0.9.111 and tree-sitter-sql 0.3.13, a partially parsed CREATE PROCEDURE can produce a malformed structured routine node alongside the correctly recovered routine. A bracketed name can absorb parameter text; an escaped quoted name can be truncated. This leaves two routine nodes for one declaration.

Reproduction

Install graphifyy 0.9.111 and tree-sitter-sql 0.3.13, then run:

from pathlib import Path
from tempfile import TemporaryDirectory
from graphify.extractors.sql import extract_sql

with TemporaryDirectory() as tmp:
    for name, sql in [("bracketed.sql", "CREATE PROCEDURE [dbo].[usp_LoadDebtors]\n    @BatchId INT\nAS\nBEGIN\n    SET NOCOUNT ON;\n    INSERT INTO dbo.Debtors (Id) SELECT Id FROM staging.Debtors;\nEND;\n"), ("quoted.sql", 'CREATE PROCEDURE "dbo"."a""b"\nAS\nBEGIN\n    SELECT 1;\nEND;\n')]:
        path = Path(tmp) / name
        path.write_text(sql, encoding="utf-8")
        result = extract_sql(path)
        print(name, sorted(n["label"] for n in result["nodes"] if n["label"].endswith("()")))

Actual result

bracketed.sql ['dbo.usp_LoadDebtors()', 'dbo.usp_LoadDebtors@BatchId INT()']
quoted.sql ['"dbo"."a""b"()', '"dbo"."a"()']

Expected result

Each declaration should yield one routine node with the complete name: dbo.usp_LoadDebtors() and "dbo"."a""b"(), respectively. Reads and writes in the procedure should remain attached to that node.

Context

The structured tree walk and the whole-file recovery scan appear to assign different identifiers to the same declaration when the grammar emits an incomplete or polluted object reference. The two existing regression tests test_sql_tsql_bracketed_procedure_is_recovered and test_sql_escaped_double_quote_in_routine_name_is_consumed fail with this grammar version. This is adjacent to #5146, which concerns write edges from structurally parsed T-SQL procedures.

Activity

  1. github-actions commented on Nov 16, 2026

    @github-actions

    Thanks for opening this issue, @sub4biz. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. sub4biz commented on Nov 21, 2026

    @sub4biz
    Author

    Retested the two examples in this issue on clean graphifyy v0.9.114 with tree-sitter-sql 0.3.13. Each now produces a single routine node with the expected name: dbo.usp_LoadDebtors() for the bracketed procedure and "dbo"."a""b"() for the escaped quoted procedure. The additional malformed or duplicate routine nodes no longer appear in these examples.

    The bracketed procedure also retains the expected writes_to dbo.Debtors and reads_from staging.Debtors edges on dbo.usp_LoadDebtors(). This covers the expected behavior in the original report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions