codeant-ai-for-open-source[bot] commented on code in PR #38531:
URL: https://github.com/apache/superset/pull/38531#discussion_r2930417518


##########
superset/mcp_service/chart/tool/get_chart_data.py:
##########
@@ -443,6 +466,10 @@ async def get_chart_data(  # noqa: C901
                     for query in query_context_json.get("queries", []):
                         query["row_limit"] = request.limit
 
+                # Merge dashboard native filters into query_context's form_data
+                qc_form_data = query_context_json.setdefault("form_data", {})
+                _apply_extra_form_data(qc_form_data, request.extra_form_data)

Review Comment:
   **Suggestion:** In the saved `query_context` path, only `form_data` is 
mutated with `extra_form_data`, but query execution uses `queries[*]`. 
`ChartDataQueryContextSchema().load()` does not rebuild filters from 
`form_data`, so dashboard filters can still be ignored. After merging into 
`form_data`, propagate the merged filter/time fields into each query before 
loading. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ Saved-chart MCP data ignores passed dashboard native filters.
   - ❌ LLM analysis uses unfiltered chart results.
   - ⚠️ New extra_form_data feature appears broken on common path.
   ```
   </details>
   
   ```suggestion
                   # Merge dashboard native filters into query_context's 
form_data
                   qc_form_data = query_context_json.setdefault("form_data", {})
                   _apply_extra_form_data(qc_form_data, request.extra_form_data)
   
                   # Keep query objects in sync with merged form_data so 
filters are applied
                   for query in query_context_json.get("queries", []):
                       query["filters"] = qc_form_data.get("filters", 
query.get("filters", []))
                       if qc_form_data.get("adhoc_filters"):
                           query["adhoc_filters"] = 
qc_form_data["adhoc_filters"]
                       if qc_form_data.get("time_range") is not None:
                           query["time_range"] = qc_form_data["time_range"]
                       if qc_form_data.get("granularity") is not None:
                           query["granularity"] = qc_form_data["granularity"]
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Invoke MCP tool `get_chart_data` (entrypoint `@tool` + `@parse_request` at
   `superset/mcp_service/chart/tool/get_chart_data.py:77-80`) with 
`extra_form_data.filters`
   for a saved chart.
   
   2. Execution enters saved-query-context branch 
(`get_chart_data.py:460-476`), because
   `chart.query_context` is loaded (`get_chart_data.py:289-295`).
   
   3. Code only mutates `query_context_json["form_data"]` 
(`get_chart_data.py:469-471`) but
   does not update `query_context_json["queries"]`.
   
   4. `ChartDataQueryContextSchema().load()` 
(`superset/charts/schemas.py:1429-1431`) calls
   `QueryContextFactory.create(**data)`; factory builds executable QueryObjects 
strictly from
   `queries` (`superset/common/query_context_factory.py:74-85`), so added 
dashboard filters
   are not applied.
   ```
   </details>
   <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_data.py
   **Line:** 469:471
   **Comment:**
        *Logic Error: In the saved `query_context` path, only `form_data` is 
mutated with `extra_form_data`, but query execution uses `queries[*]`. 
`ChartDataQueryContextSchema().load()` does not rebuild filters from 
`form_data`, so dashboard filters can still be ignored. After merging into 
`form_data`, propagate the merged filter/time fields into each query before 
loading.
   
   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.
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38531&comment_hash=3d1b37f29092b26aec412fae64f7add73c886d89400aadbdac092bbfc64a3398&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38531&comment_hash=3d1b37f29092b26aec412fae64f7add73c886d89400aadbdac092bbfc64a3398&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]

Reply via email to