codeant-ai-for-open-source[bot] commented on code in PR #42576:
URL: https://github.com/apache/superset/pull/42576#discussion_r3677321969
##########
superset/mcp_service/chart/tool/get_chart_preview.py:
##########
@@ -218,6 +218,34 @@ def _build_query_metrics(form_data: Dict[str, Any]) ->
list[Metric]:
return metrics
+def _query_context_has_fields(query_context: Any) -> bool:
+ """Return True if at least one query has metrics or columns configured.
+
+ A chart with neither (e.g. a big_number chart saved without a metric)
+ cannot be previewed; downstream query execution would only surface a
+ generic "empty query" error.
+ """
+ queries = getattr(query_context, "queries", None)
+ if not queries:
+ # No queries to inspect (or an object without a `.queries`
+ # attribute, e.g. a test double) — defer to normal query
+ # execution rather than guessing.
+ return True
+ return any((query.metrics or query.columns) for query in queries)
Review Comment:
**Suggestion:** The `any(...)` check allows a multi-query context to proceed
when only a secondary query has metrics or columns. Mixed-timeseries contexts
can therefore contain an empty primary query; `ChartDataCommand` still executes
that invalid query and may return an error, while the preview later reads only
`result["queries"][0]`, potentially ignoring the query that has data. Require
every query that will be executed to have fields, or filter/handle empty
queries and select the populated result consistently. [incorrect condition
logic]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Mixed-timeseries previews may execute an empty primary query.
- ⚠️ Populated secondary query results can be ignored.
- ⚠️ ASCII and table previews may return generic query errors.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=06297a0dd64e49518ae23c32c8122819&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=06297a0dd64e49518ae23c32c8122819&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/mcp_service/chart/tool/get_chart_preview.py
**Line:** 234:234
**Comment:**
*Incorrect Condition Logic: The `any(...)` check allows a multi-query
context to proceed when only a secondary query has metrics or columns.
Mixed-timeseries contexts can therefore contain an empty primary query;
`ChartDataCommand` still executes that invalid query and may return an error,
while the preview later reads only `result["queries"][0]`, potentially ignoring
the query that has data. Require every query that will be executed to have
fields, or filter/handle empty queries and select the populated result
consistently.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42576&comment_hash=5c93af4d813fafd48cd3f8419f267f6962d4948b2a46275143d1ab044dd02436&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42576&comment_hash=5c93af4d813fafd48cd3f8419f267f6962d4948b2a46275143d1ab044dd02436&reaction=dislike'>👎</a>
##########
tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py:
##########
@@ -1041,6 +1166,51 @@ def test_build_query_metrics_empty():
assert _build_query_metrics({}) == []
+def test_query_context_has_fields_true_with_metrics():
+ query_context = SimpleNamespace(
+ queries=[SimpleNamespace(metrics=["count"], columns=[])]
+ )
+ assert _query_context_has_fields(query_context) is True
+
+
+def test_query_context_has_fields_true_with_columns():
+ query_context = SimpleNamespace(
+ queries=[SimpleNamespace(metrics=[], columns=["region"])]
+ )
+ assert _query_context_has_fields(query_context) is True
+
+
+def test_query_context_has_fields_false_when_both_empty():
+ query_context = SimpleNamespace(queries=[SimpleNamespace(metrics=[],
columns=[])])
+ assert _query_context_has_fields(query_context) is False
+
+
+def test_query_context_has_fields_true_when_any_query_has_fields():
+ # Mixed timeseries has two queries; a preview is still useful if only
+ # one of them has metrics/columns.
+ query_context = SimpleNamespace(
+ queries=[
+ SimpleNamespace(metrics=[], columns=[]),
+ SimpleNamespace(metrics=["count"], columns=[]),
+ ]
+ )
Review Comment:
**Suggestion:** The test accepts a query context when only a later query has
fields, but both preview strategies extract and render only
`result["queries"][0]`. A mixed-timeseries context with an empty first query
can therefore still fail during execution or produce an empty preview while
this test reports success. The test should require fields in the query that the
preview actually renders, or assert the intended handling of every query.
[incorrect condition logic]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Unit test can mask empty first-query previews.
- ⚠️ Mixed-timeseries preview behavior remains under-tested.
- ⚠️ Future query-selection regressions may pass CI.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=4dcb5925dfb04273879cadb9f8225e08&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=4dcb5925dfb04273879cadb9f8225e08&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py
**Line:** 1188:1196
**Comment:**
*Incorrect Condition Logic: The test accepts a query context when only
a later query has fields, but both preview strategies extract and render only
`result["queries"][0]`. A mixed-timeseries context with an empty first query
can therefore still fail during execution or produce an empty preview while
this test reports success. The test should require fields in the query that the
preview actually renders, or assert the intended handling of every query.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42576&comment_hash=d539ea3c081d159cb402fd161bab36b06cac5246515ab271d8f94fdc90c0593f&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42576&comment_hash=d539ea3c081d159cb402fd161bab36b06cac5246515ab271d8f94fdc90c0593f&reaction=dislike'>👎</a>
--
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]