You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "eschutho (via GitHub)" <gi...@apache.org> on 2026/09/20 15:12:24 UTC
[PR] fix(mcp): catch ValueError for reversed date range in query_dataset [superset]
eschutho opened a new pull request, #44462:
URL: https://github.com/apache/superset/pull/44462
### SUMMARY
The `query_dataset` MCP tool logged a full-traceback ERROR event and returned a
generic `UnexpectedError` to the calling client whenever a caller supplied an
explicit reversed time range (a `"<start> : <end>"` range where `start > end`,
e.g. `"2024-01-01T00:00:00 : 2020-01-01T00:00:00"`). This is benign, actionable
user/agent-input, not a bug — but it was being treated as an unexpected server
error.
**Root cause**
`superset/utils/date_parser.py::get_since_until()` raises a bare
`ValueError("From date cannot be larger than to date")` when `since > until`.
`query_dataset()` reaches this parser transitively:
```
query_dataset() -> build_query_dict()/execute_tabular_query()
-> QueryContextFactory.create()
-> QueryObjectFactory.create()
-> get_since_until_from_time_range()
-> date_parser.get_since_until() # raises ValueError
```
`query_dataset()`'s exception handling had specific arms for
`OAuth2RedirectError`, `OAuth2Error`, `(CommandException, SupersetException)`,
and `SQLAlchemyError`, but **not** `ValueError`. A reversed range therefore fell
through to the generic `except Exception`, which calls `logger.exception(...)`
(an ERROR-level, full-traceback log captured as a Sentry event) and returns an
unhelpful generic `UnexpectedError` to the LLM client.
This is the same root-cause family as #43517 (which added an `except ValueError`
arm in `ChartDataRestApi._create_query_context_from_form` to convert an
unhandled 500 into a 400), but #43517 only covered the REST `ChartDataRestApi.data`
call path — not this separate MCP tool call path, which remained a live gap.
Note: the pydantic-level guard `common/time_range_validation.py::validate_time_range()`
intentionally does *not* validate explicit `"<start> : <end>"` ranges — its
docstring defers any parse failure to the downstream parser as "a signal the
caller can act on". So the deferred-to-downstream `ValueError` is by design; it
just wasn't being converted into a clean, actionable result at the MCP boundary.
**Fix**
Add a specific `except ValueError as exc:` arm before the generic
`except Exception`, mirroring the sibling-tool pattern already used in
`dashboard/tool/update_dashboard.py` and
`dashboard/tool/apply_dashboard_filters.py`. It:
- does **not** call `logger.exception` (this is expected input validation, not a
bug — no noisy full-traceback event)
- emits a lightweight `await ctx.error(...)`, matching the other arms' style
- returns `DatasetError.create(error=str(exc), error_type="ValidationError")`,
surfacing the actual, actionable message to the client
### TRADEOFFS
- **Failure-mode change (intended):** previously an unhandled reversed-range
`ValueError` produced a full-traceback ERROR log plus a generic
`UnexpectedError` result. Now it produces a clean `ValidationError` result
carrying the parser's own message and no traceback log. This is the whole
point of the change — a reversed date range is benign, actionable input, so it
should not generate error-level noise or look like a server bug to the client.
- **Scope of the `ValueError` catch:** the arm is function-wide, covering the
whole `try` block (dataset lookup, name validation, filter/query construction,
execution, and formatting), rather than wrapping only the
`execute_tabular_query` call. This is deliberate and consistent with how the
sibling MCP tools (`update_dashboard`, `apply_dashboard_filters`) catch
`ValueError` function-wide. A `ValueError` raised anywhere in this block is
fundamentally a malformed-input signal, and because the message is passed
through verbatim (`str(exc)`), the client always receives the real message
rather than a misleading one — so a broad catch does not mask an unrelated
error behind a wrong label; it just classifies it as a validation problem,
which is accurate for `ValueError`. The more specific `SupersetException`,
`CommandException`, and `SQLAlchemyError` arms remain ordered before it, so
domain and database errors keep their existing, more specific handling.
### TESTING INSTRUCTIONS
Added `test_query_dataset_reversed_time_range` to
`tests/unit_tests/mcp_service/dataset/tool/test_query_dataset.py`. It calls
`query_dataset` with `time_range="2024-01-01T00:00:00 : 2020-01-01T00:00:00"`
(which passes the pydantic `validate_time_range` guard unchanged and reaches the
real `get_since_until()`), and asserts the result is a `DatasetError` with
`error_type="ValidationError"` and a message containing
"From date cannot be larger than to date" (not a raised exception, not
`UnexpectedError`).
Commands run:
```
$ python3 -m pytest tests/unit_tests/mcp_service/dataset/tool/test_query_dataset.py::test_query_dataset_reversed_time_range -q
1 passed in 1.37s
$ python3 -m pytest tests/unit_tests/mcp_service/dataset/tool/test_query_dataset.py -q
103 passed, 1 skipped in 21.27s
$ ruff check <touched files>
All checks passed!
$ ruff format --check <touched files>
2 files already formatted
```
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): catch ValueError for reversed date range in query_dataset [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #44462:
URL: https://github.com/apache/superset/pull/44462#discussion_r4057624532
##########
superset/mcp_service/dataset/tool/query_dataset.py:
##########
@@ -433,6 +433,17 @@ async def query_dataset( # noqa: C901
error_type="DatabaseError",
)
+ except ValueError as exc:
+ # Expected user/agent-input validation (e.g. a reversed time_range where
+ # since > until raises "From date cannot be larger than to date" from
+ # date_parser.get_since_until). Return an actionable ValidationError
+ # without a full-traceback log — this is not a bug.
+ await ctx.error("Invalid request: %s" % (str(exc),))
Review Comment:
This `try` spans ~282 lines, including all of `execute_tabular_query`, so an unanticipated `ValueError` (pydantic's subclasses it) reaches here too — reported to the agent as its own `ValidationError`, with no traceback anywhere. One line keeps those diagnosable:
```suggestion
logger.warning("Invalid request while querying dataset: %s", exc)
await ctx.error("Invalid request: %s" % (str(exc),))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): catch ValueError for reversed date range in query_dataset [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44462:
URL: https://github.com/apache/superset/pull/44462#issuecomment-5751680664
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): catch ValueError for reversed date range in query_dataset [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #44462:
URL: https://github.com/apache/superset/pull/44462#issuecomment-5750684268
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/44462?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `0%` with `3 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 57.31%. Comparing base ([`4511c13`](https://app.codecov.io/gh/apache/superset/commit/4511c1381930ec53cd74c1e25c3ad4397768e2b4?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`863cf78`](https://app.codecov.io/gh/apache/superset/commit/863cf78336df3301dfeb26f476a6ff270e11a97f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/44462?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [superset/mcp\_service/dataset/tool/query\_dataset.py](https://app.codecov.io/gh/apache/superset/pull/44462?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fdataset%2Ftool%2Fquery_dataset.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvZGF0YXNldC90b29sL3F1ZXJ5X2RhdGFzZXQucHk=) | 0.00% | [3 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/44462?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
> :exclamation: There is a different number of reports uploaded between BASE (4511c13) and HEAD (863cf78). Click for more details.
>
> <details><summary>HEAD has 112 uploads less than BASE</summary>
>
>| Flag | BASE (4511c13) | HEAD (863cf78) |
>|------|------|------|
>|python|98|1|
>|presto|16|1|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #44462 +/- ##
===========================================
- Coverage 80.65% 57.31% -23.34%
===========================================
Files 2942 2942
Lines 175692 175695 +3
Branches 40788 40788
===========================================
- Hits 141705 100705 -41000
- Misses 31325 74030 +42705
+ Partials 2662 960 -1702
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/44462/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/44462/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/44462/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/44462/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/44462/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.03% <0.00%> (-0.01%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/44462/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.03% <0.00%> (-45.93%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/44462/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit](https://app.codecov.io/gh/apache/superset/pull/44462/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/44462?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): catch ValueError for reversed date range in query_dataset [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44462:
URL: https://github.com/apache/superset/pull/44462#issuecomment-5750652936
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): catch ValueError for reversed date range in query_dataset [superset]
Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho merged PR #44462:
URL: https://github.com/apache/superset/pull/44462
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org