codeant-ai-for-open-source[bot] commented on code in PR #42822: URL: https://github.com/apache/superset/pull/42822#discussion_r3763620873
########## superset/charts/data/form_data.py: ########## @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from typing import Any, TYPE_CHECKING + +from flask import g + +if TYPE_CHECKING: + from superset.common.query_context import QueryContext + + +def set_form_data(form_data: dict[str, Any]) -> None: + """Expose chart data request fields to Jinja template macros.""" + g.form_data = form_data + + +def set_query_context_form_data( + query_context: QueryContext, + datasource_id: int, + datasource_type: str, +) -> None: + """Expose a programmatically-created query like a chart data API request.""" + set_form_data( + { + "datasource": {"id": datasource_id, "type": datasource_type}, + "queries": [ + query.to_dict() for query in getattr(query_context, "queries", []) Review Comment: **Suggestion:** Serializing each `QueryObject` with `to_dict()` drops fields that Jinja macros depend on, including `time_range` (the method's returned dictionary does not contain that field). When a query context stores the time range on the query object rather than in `QueryContext.form_data`, `get_time_filter()` sees no time range and silently falls back to `No filter`, causing templated SQL to use the wrong time window. Preserve the complete query representation or explicitly copy the omitted macro-relevant fields. [data type] <details> <summary><b>Severity Level:</b> Major ⚠️</summary> ```mdx - ❌ MCP-templated SQL can lose requested time bounds. - ❌ `get_time_filter()` may generate unbounded queries. - ⚠️ Results differ from equivalent chart API queries. ``` </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d9b71360924b4e498f4df6b96ba077d3&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=d9b71360924b4e498f4df6b96ba077d3&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/charts/data/form_data.py **Line:** 43:43 **Comment:** *Data Type: Serializing each `QueryObject` with `to_dict()` drops fields that Jinja macros depend on, including `time_range` (the method's returned dictionary does not contain that field). When a query context stores the time range on the query object rather than in `QueryContext.form_data`, `get_time_filter()` sees no time range and silently falls back to `No filter`, causing templated SQL to use the wrong time window. Preserve the complete query representation or explicitly copy the omitted macro-relevant fields. 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%2F42822&comment_hash=699a0d23550baafc1a719f05fc18b7fa63a0a88f593fa22f6cb8096a2aff78b9&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42822&comment_hash=699a0d23550baafc1a719f05fc18b7fa63a0a88f593fa22f6cb8096a2aff78b9&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]
