[BUGFIX] query asset SQL ending in a comment fails validation #12124
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
nanjeshramesh
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:
(ran it locally). Compiles correctly against the PostgreSQL dialect
too, though I don't have a local Postgres to actually run it
against.
either way.
this already worked.
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.