codeant-ai-for-open-source[bot] commented on code in PR #44460:
URL: https://github.com/apache/superset/pull/44460#discussion_r4057089318
##########
superset/common/query_context_factory.py:
##########
@@ -275,6 +275,39 @@ def _apply_granularity( # noqa: C901
query_object.granularity = main_dttm_col
return
+ if (
+ not x_axis
+ and query_object.granularity is None
+ and query_object.is_timeseries
+ ):
+ # A chart saved before the x-axis control existed keeps its time
+ # column in ``form_data`` under the legacy ``granularity_sqla`` key
+ # and never wrote it into the stored query object. The paths that
+ # rebuild a query from form data resolve that key
+ # (``extractExtras.ts`` for Explore, ``form_data_query_context``
for
+ # the Excel export and MCP tools), but anything that replays the
+ # stored ``query_context`` verbatim reaches the
+ # ``not granularity and is_timeseries`` guard in ``models/helpers``
+ # and fails with "Datetime column not provided as part table
+ # configuration". Resolving the legacy key here, and only then the
+ # dataset's main datetime column, gives both kinds of consumer the
+ # same time subject. Candidates are matched against the dataset's
+ # temporal columns so one that has since been dropped, or is no
+ # longer temporal, is ignored.
+ candidates = (
+ (form_data or {}).get("granularity_sqla"),
+ (form_data or {}).get("granularity"),
+ getattr(datasource, "main_dttm_col", None),
+ )
+ query_object.granularity = next(
+ (
+ candidate
+ for candidate in candidates
+ if candidate in temporal_columns
+ ),
+ None,
+ )
Review Comment:
**Suggestion:** When fallback selects a granularity without an x-axis, the
downstream path removes the first temporal filter, potentially deleting an
independent filter on another datetime column.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Logic error`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f267cc6533844e1889133eac8b86a230&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=f267cc6533844e1889133eac8b86a230&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/common/query_context_factory.py
**Line:** 302:309
**Comment:**
*Logic Error: When fallback selects a granularity without an x-axis,
the downstream path removes the first temporal filter, potentially deleting an
independent filter on another datetime column.
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%2F44460&comment_hash=f37c43617882a216dacf62367557f8160b86ba650e1c63e1c906b93a63bb1180&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44460&comment_hash=f37c43617882a216dacf62367557f8160b86ba650e1c63e1c906b93a63bb1180&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]