← Back to Pull requests

[BUGFIX] query asset SQL ending in a comment fails validation #12124

Closed
unknown closed this pull request without merging on Sep 03, 2026 10:56 UTC
View on GitHub
unknown unknown commented on Aug 29, 2026 00:01 UTC
Author

Closes #12122.

Turned out there are two separate places doing the wrap, not the
three called out in the issue.

get_domain_records, resolve_metric_bundle, and _count_query_parameters
each independently wrap a raw TextClause into a subquery via
.columns().subquery(). Those are the three sites named in the issue,
now sharing one helper (_wrap_raw_sql_as_subquery).

_subselectable does effectively the same thing but through
sa.select(sa.text(...)).subquery() instead, since it works with a
plain string, not a TextClause, so it never triggered the isinstance
check the other three sites use. This is the path SQLite takes for
query assets specifically: its partition clause is sa.text("1 = 1"),
never sa.true(), so the early return that skips this method never
fires. That's why the repro in the issue failed on SQLite the way it
did.

Both paths now go through _ensure_sql_text_ends_with_newline before
wrapping, so a comment that runs to the end of the text can't reach
whatever gets appended after it.

What I checked:

  • Trailing -- comment: fails before the fix, passes after, on SQLite

  • (ran it locally). Compiles correctly against the PostgreSQL dialect
    too, though I don't have a local Postgres to actually run it
    against.
  • Comment in the middle of the query, followed by more SQL: unaffected

  • either way.
  • Trailing / ... / comment that's properly closed: also unaffected,

  • this already worked.
  • Trailing unterminated /* comment (never closed): still broken. A

  • newline can't fix this one, since nothing after an unclosed block
    comment is ever "safe" no matter how many lines you add. Actually
    closing it would need real comment-state parsing, which felt like
    more than this fix should take on. Flagging it in case it's worth
    its own issue.

    New test file:
    tests/integration/data_sources_and_expectations/data_sources/test_query_asset_sql_comments.py,
    covering the first three cases above against both SQLite and
    Postgres.

    Diff: 244 lines (+183 / -61) across 3 files Reviewer: nanjeshramesh Review duration: 7855m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.39) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 244 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.329
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #12124"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 38.8% (MEDIUM) · Higher = larger blast radius
    38.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.8% · Safe to merge
    16.8%