sadpandajoe opened a new pull request, #43353: URL: https://github.com/apache/superset/pull/43353
<!--- Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/ Example: fix(dashboard): load charts correctly --> ### SUMMARY A metric shaped like a Custom SQL ad-hoc metric (carries `sqlExpression`, `aggregate`, or `column`) but missing `expressionType` was silently coerced by `QueryObject._set_metrics` into a bare string, on the assumption it was a legacy `{"label": "name"}` reference to a saved metric. For a Custom SQL metric the label is the SQL expression text itself, so metric resolution then looked that text up among the dataset's saved metrics, found nothing, and raised a misleading `Metric '<sql text>' does not exist` error instead of a clear validation error. This PR narrows the coercion: a dict carrying any ad-hoc-only key (`sqlExpression`, `aggregate`, `column`) but missing `expressionType` is now rejected with a `QueryObjectValidationError` naming the metric and the missing field. The chart-data API endpoints already catch `QueryObjectValidationError` around query-context deserialization, so the error surfaces as a clean 400 response instead of the previous misleading failure. The legacy `{"label": "name"}` saved-metric reference (no ad-hoc keys at all) still resolves exactly as before. ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF N/A — backend validation change, not a UI change. ### TESTING INSTRUCTIONS 1. `pytest tests/unit_tests/charts/data/malformed_adhoc_metric_test.py -v` 2. `pytest tests/unit_tests/common/test_query_object_factory.py -v` The new test file covers: a malformed ad-hoc metric now raises a clear validation error instead of silently resolving to a bogus saved-metric lookup; the pre-existing legacy label-only reference still resolves correctly; a well-formed Custom SQL metric is unaffected. ### ADDITIONAL INFORMATION <!--- Check any relevant boxes with "x" --> <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue --> - [ ] 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
