Skip to content

Fixes #32064: [MSSQL] Keep stored-procedure lineage when the engine returns no procedure body - #33369

Merged
mohittilala merged 3 commits into
mainfrom
fix/32064-mssql-sp-lineage-null-procedure-text
Sep 16, 2026
Merged

mohittilala merged 3 commits into
mainfrom
fix/32064-mssql-sp-lineage-null-procedure-text

Conversation

@mohittilala

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #32064

sys.dm_exec_sql_text() returns a NULL text column for encrypted and CLR modules, and the MSSQL plan-cache statement selects it as PROCEDURE_TEXT. Since QueryByProcedure.procedure_text was required, those rows failed validation and the lineage run finished with failures.

The rows were usable. The body is only a fallback for deriving the procedure name, and they already carried both the name and the query text that lineage is parsed from. So procedure_name and procedure_text are now str | None, because either one alone identifies the procedure, and the name fallback only parses a body when there is one.

procedure_name was already str = Field(None, ...), which tolerated an absent key but not an explicit NULL from the database. Making the annotation honest also let a pyright: ignore go.

Failures now name the procedure they came from: Error trying to get procedure name for [usp_broken] due to [...].

query_text and query_type stay required, since a row with no query text carries no lineage.

Type of change:

  • Bug fix

High-level design:

N/A, small change.

Tests:

Use cases covered

  • An MSSQL instance with an encrypted or CLR stored procedure completes lineage instead of failing, and that procedure's query history is processed rather than discarded.
  • Query history reporting no procedure name still resolves it from the body.
  • Query history reporting neither name nor body no longer raises.
  • A row that genuinely cannot be used names its procedure in the failure.

Unit tests

  • I added unit tests for the new/changed logic.
  • ingestion/tests/unit/lineage/test_stored_procedure_lineage.py, new TestProcedureBodyUnavailable (5 tests, 4 red before this change).
  • ingestion/tests/unit/lineage/ plus MSSQL topology tests: 507 passed, 2 skipped.

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

  • Not applicable, covered by unit tests against the real mixin plus the manual run below.

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

On a SQL Server 2019 container with two stored procedures differing only in WITH ENCRYPTION, the plain one as a control group.

  1. Confirmed sys.dm_exec_sql_text().text and OBJECT_DEFINITION() are both NULL for the encrypted procedure and non-NULL for the plain one.
  2. Drove MSSQL_GET_STORED_PROCEDURE_QUERIES verbatim through the real yield_stored_procedure_queries() and reproduced the reported error from a real connector row: 0 yielded, 1 failure.
  3. Same flow with this change: the row is yielded, no failure recorded.
  4. Before/after over both procedures at once. Before: only the plain one yielded, 1 failure. After: both yielded, 0 failures.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added a test that covers the exact scenario we are fixing.

…eturns no procedure body

sys.dm_exec_sql_text() returns a NULL text column for encrypted and CLR modules,
and the MSSQL plan-cache statement selects it as PROCEDURE_TEXT, so those rows
failed validation and the lineage run finished with failures. The rows were
usable: the body is only a fallback for deriving the procedure name, and they
already carried the name and the query text that lineage is parsed from.

procedure_name and procedure_text are now str | None, since either one alone
identifies the procedure, and the name fallback only parses a body when there is
one. Failures now name the procedure they came from.
Copilot AI lite review requested due to automatic review settings September 15, 2026 21:04
@mohittilala
mohittilala requested a review from a team as a code owner September 15, 2026 21:04
@mohittilala mohittilala self-assigned this Sep 15, 2026
@github-actions github-actions Bot added the safe to test Add this label to run secure Github workflows on PRs label Sep 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical issue remains because row conversion must stay inside the per-row error handler to prevent lineage runs from aborting.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes MSSQL stored-procedure lineage failures when procedure bodies are unavailable.

Changes:

  • Allows nullable procedure names and bodies.
  • Preserves fallback name parsing and improves failure diagnostics.
  • Adds regression tests for missing procedure metadata.
File summaries
File Description
ingestion/tests/unit/lineage/test_stored_procedure_lineage.py Adds regression coverage for unavailable procedure bodies and metadata.
ingestion/src/metadata/ingestion/source/database/stored_procedures_mixin.py Handles nullable procedure metadata and reports procedure-specific errors.
ingestion/src/metadata/ingestion/source/database/lineage_processors.py Makes procedure name and body fields optional.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Reading the row outside the try narrowed the protection the per-row handler
exists for: the producer consumes this as a generator, so an exception escaping
here drops every remaining row while the run still reports success. row_data is
now bound before the try and assigned inside it, so the diagnostic still names
the procedure.
Copilot AI review requested due to automatic review settings September 15, 2026 21:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved issues were identified, and regression coverage is included.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 29e3c8e4f72c23d549a2e714568880d6c6a98ddc in Playwright run 35048587126, attempt 1.

✅ 109 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 47m 33s

⏱️ Max setup 4m 23s · max shard execution 12m 52s · max shard-job elapsed before upload 17m 46s · reporting 3s

🌐 238.77 requests/attempt · 1.77 app boots/UI scenario · 0.00% common-shard skew

Optimization targets still in progress:

  • Browser traffic was 238.77 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 1.77 per UI scenario (213 boots / 120 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 46 0 0 0 0 0
✅ Shard ingestion-01 29 0 0 0 0 0
✅ Shard ingestion-02 34 0 0 0 0 0

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

Copilot AI review requested due to automatic review settings September 16, 2026 02:35
@gitar-bot

gitar-bot Bot commented Sep 16, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Fixes MSSQL stored-procedure lineage extraction when the engine returns no procedure body by making procedure_name and procedure_text optional. Encrypted and CLR modules now yield usable lineage rows instead of failing validation, with improved error messages that name the procedure involved. Comprehensive unit tests cover the new behavior. No issues found.

Review coverage

Rules No rules evaluated

Functional validation Not enabled · Set up

Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Final human review is warranted for the lineage extraction changes.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@sonarqubecloud

Copy link
Copy Markdown

@mohittilala
mohittilala added this pull request to the merge queue Sep 16, 2026
)
row_data = row._asdict()
query_by_procedure = QueryByProcedure.model_validate(row_data)
if not query_by_procedure.procedure_name and query_by_procedure.procedure_text:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: when neither is there, the row just quietly disappears further down at the continue in the producer. probably fine, but a debug log there wouldn't hurt.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fair point, it does vanish silently there. leaving it out of this one since it's in the queue, will add the debug log in a follow-up

Merged via the queue into main with commit 4d886c7 Sep 16, 2026
121 checks passed
@mohittilala
mohittilala deleted the fix/32064-mssql-sp-lineage-null-procedure-text branch September 16, 2026 06:18

This branch was previously deployed

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

Labels

bug Something isn't working connector:mssql feature:lineage Ingestion safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlserver lineage abort validation error for QueryByProcedure

3 participants