Repository navigation
fix(mcp): expose resolved query time boundaries - #44105
aminghadersohi merged 4 commits into
Conversation
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #44105 +/- ##
========================================
Coverage 80.09% 80.09%
========================================
Files 2922 2922
Lines 171996 172204 +208
Branches 39911 39960 +49
========================================
+ Hits 137765 137935 +170
- Misses 31653 31684 +31
- Partials 2578 2585 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
gabotorresruiz
left a comment
There was a problem hiding this comment.
LGTM. The engine has carried from_dttm/to_dttm in the result payload since 2021 and MCP was just dropping them, so forwarding them is the right fix.
I verified the resolution independently under a frozen clock: Last month (rolling), previous calendar month, Last year, Current year, an explicit range, and the no-range case all resolve to exactly the bounds the new tests assert, and the schema serializes datetime to ISO 8601 and null to null. Both execute_tabular_query callers (query_dataset, get_table) are covered, and the values leak nothing beyond the caller's own input, so no boundary concern.
One non-blocking note. The cache-hit caveat is documented in the PR body and the .mdx, but the model reads the field description, and to_dttm's says "Report these bounds when describing results" with no mention of the cache case. I verified QueryObject.cache_key deletes from_dttm/to_dttm and keys on the relative time_range string, so a query_dataset call with time_range="Last month" served from cache across a day rollover returns the earlier cached rows while from_dttm/to_dttm report the new day's resolved range. Since performance.cache_status already surfaces the hit, one sentence in the description would close it, e.g. "On a cache hit these bounds reflect the current request; cross-check performance.cache_status." Purely the description, no behavior change. Approving regardless.
|
Thanks @gabotorresruiz — addressed in d2f02a5. Both response schemas now include the cache-hit caveat in the model-facing |
|
The flagged issue is correct: the test case for cached results only verifies the |
|
@gabotorresruiz Thanks for the careful verification. Updated both This explicitly covers the rollover case you verified: Validation: |
|
Addressed the review comments in d4b228a. The cache-serialization suggestion is covered by a real cache write/read regression test across a frozen-clock rollover, for both populated and empty results; details are in the review-thread reply. The external one-sided-range report does not reproduce through MCP validation, so I added entry-point regression tests and clarified the documentation rather than changing query behavior. @gabotorresruiz Both bound descriptions retain the explicit rollover caveat. They point to Validation: 134 targeted tool tests passed with the local |
Code Review Agent Run #92bfa8Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
… its cache With the bounds in the cache key, "Last month" spanning midnight is a distinct query rather than a cache hit, so the from_dttm/to_dttm a response reports are the ones its rows were queried for. This is the cached-execution provenance follow-up deferred by apache#44105.
SUMMARY
The query engine resolves a relative time range to concrete bounds, but MCP discarded them. Callers could not tell which range produced the numbers: a model can narrate one range while the query used another.
Verified on
master:from_dttm/to_dttmappear nowhere insuperset/mcp_service/, whilesuperset/common/query_context_processor.pycomputes the result payload containing those resolved bounds.Both
query_datasetandget_tablereturnfrom_dttm(inclusive) andto_dttm(exclusive), including on cached and empty results. The response schemas and tool documentation explain how to report these ISO 8601 values. Missing primary bounds remain null.What this does not do: no parser change; no year-offset bug was found. Callers can identify the engine's primary logical range, not every additional SQL filter or timezone-adjusted boundary. These fields are not observed row minima/maxima, and naive timestamps are not asserted to be UTC. Additional column filters, virtual dataset SQL, and semantic-view one-sided ranges rewritten as comparison filters can still constrain results.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable (MCP response metadata only).
Before: the request's relative expression was available, but the resolved primary bounds were omitted.
After: for example,
previous calendar monthevaluated on July 17, 2026 returnsfrom_dttm: "2026-06-01T00:00:00"andto_dttm: "2026-07-01T00:00:00"(exclusive).TESTING INSTRUCTIONS
pytest -q tests/unit_tests/mcp_service/dataset/tool/test_query_dataset.py tests/unit_tests/mcp_service/semantic_layer/tool/test_get_table.py.query_datasetand a relativetime_range; compare the returned bounds with the engine result and generated primary time predicate.get_tablefor a built-in dataset and an external semantic view.Validation: all changed-file
uvx pre-commit run --files ...hooks passed, including mypy and pylint. Targeted unit tests: 128 passed (PYTHONPATH=.:superset-core/src /tmp/ssvenv/bin/pytest -qwith the two files above). A live-server check was unavailable because no service was listening on localhost:8088.ADDITIONAL INFORMATION
Additive response fields only; no database migration or date-parser changes.
Deferred follow-ups (outside this PR)
from_dttm/to_dttmvalues from its cache key and assembles these response fields from the requesting query object. A cache hit spanning a relative-range rollover can therefore report the requesting range rather than the original cached execution's bounds. This PR forwards the engine's metadata unchanged; it does not establish historical execution provenance. Investigating cache identity/provenance belongs in a separate change.get_tablenull assertions, and timezone-aware serialization cases could strengthen coverage separately. The added cached-result cases use mocked execution payloads.Review: one adversarial review round found no substantive in-scope defects in cached/empty forwarding, boundary semantics, or serialization. That round required no changes. The subsequent maintainer review requested a model-facing cache caveat: both
to_dttmfield descriptions and the query-date documentation explain that cache-hit bounds reflect the requesting range, not necessarily the original cached execution, and point tocache_status.cache_hit. No query or parser behavior changed. Changed-file pre-commit and all 128 targeted unit tests passed again after this update.