codeant-ai-for-open-source[bot] commented on code in PR #43478:
URL: https://github.com/apache/superset/pull/43478#discussion_r3846243987
##########
superset/mcp_service/chart/tool/get_chart_sql.py:
##########
@@ -168,8 +175,40 @@ def _sql_from_saved_query_context(
qc_json["result_type"] = ChartDataResultType.QUERY
qc_json["force"] = False
- query_context = ChartDataQueryContextSchema().load(qc_json)
+ if extra_form_data:
+ try:
+ for query in qc_json.get("queries", []):
+ merge_extra_form_data_filters_into_query(
+ query,
+ extra_form_data,
+ qc_json["datasource"]["id"],
+ qc_json["datasource"]["type"],
+ )
+ except (AttributeError, KeyError, TypeError) as ex:
+ return ChartError(
+ error=f"Invalid extra_form_data filter: {ex}",
+ error_type="ValidationError",
+ )
Review Comment:
**Suggestion:** When a saved query context is structurally stale or contains
a malformed query, merging `extra_form_data` can raise `AttributeError`,
`KeyError`, or `TypeError`. Returning `ChartError` here bypasses the documented
form-data fallback, so charts with valid `chart.params` can fail instead of
rendering SQL from their saved form data. Treat these failures like schema
validation failures and return `None` so the caller rebuilds the query context.
[api mismatch]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Filtered SQL generation fails for stale saved contexts.
- ⚠️ Valid chart form data fallback is bypassed.
- ⚠️ `get_chart_sql` returns a validation error instead of SQL.
```
</details>
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=17337ff15d274203b711bc3f3f28bdcc&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=17337ff15d274203b711bc3f3f28bdcc&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<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_sql.py
**Line:** 178:191
**Comment:**
*Api Mismatch: When a saved query context is structurally stale or
contains a malformed query, merging `extra_form_data` can raise
`AttributeError`, `KeyError`, or `TypeError`. Returning `ChartError` here
bypasses the documented form-data fallback, so charts with valid `chart.params`
can fail instead of rendering SQL from their saved form data. Treat these
failures like schema validation failures and return `None` so the caller
rebuilds the query context.
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%2F43478&comment_hash=0519d780d456f0d3bd8115fc5379702aea67b3be26f9929dca16c44b39b54f5a&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43478&comment_hash=0519d780d456f0d3bd8115fc5379702aea67b3be26f9929dca16c44b39b54f5a&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]