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


##########
superset/mcp_service/dashboard/tool/apply_dashboard_filters.py:
##########
@@ -224,6 +227,65 @@ def _time_data_mask(conf: dict[str, Any], time_range: str) 
-> dict[str, Any]:
     }
 
 
+def _range_data_mask(
+    conf: dict[str, Any], bounds: list[int | float | None]
+) -> dict[str, Any]:
+    """Build the data mask a filter_range filter produces for ``bounds``.
+
+    Mirrors the frontend's ``getRangeExtraFormData``: distinct non-null
+    bounds become a pair of ``>=``/``<=`` predicates, equal non-null bounds
+    collapse to a single ``==`` predicate, and two null bounds produce no
+    predicate at all (the "required filter, nothing chosen" state when the
+    filter is marked ``enableEmptyFilter``, raised rather than guessed).
+    """
+    targets = [target for target in (conf.get("targets") or []) if target]
+    column = (targets[0].get("column") or {}).get("name") if targets else None
+    if not column:
+        raise _FilterApplyError(
+            f"Filter '{conf.get('name') or conf.get('id')}' has no target "
+            "column, so a value cannot be applied to it."
+        )
+
+    lower, upper = bounds
+    if lower is None and upper is None:
+        if (conf.get("controlValues") or {}).get("enableEmptyFilter"):
+            raise _FilterApplyError(
+                f"Filter '{conf.get('name') or conf.get('id')}' requires a "
+                "value and cannot be cleared."
+            )
+        return {"extraFormData": {}, "filterState": {"value": [None, None]}}
+
+    filters: list[dict[str, Any]] = []
+    if lower == upper:
+        filters.append({"col": column, "op": "==", "val": upper})
+    else:
+        if lower is not None:
+            filters.append({"col": column, "op": ">=", "val": lower})
+        if upper is not None:
+            filters.append({"col": column, "op": "<=", "val": upper})
+
+    return {
+        "extraFormData": {"filters": filters},
+        "filterState": {"value": [lower, upper]},
+    }
+
+
+def _timegrain_data_mask(
+    conf: dict[str, Any], time_grain: Sequence[str]
+) -> dict[str, Any]:
+    """Build the data mask a filter_timegrain filter produces for 
``time_grain``."""
+    is_set = bool(time_grain)
+    if not is_set and (conf.get("controlValues") or 
{}).get("enableEmptyFilter"):
+        raise _FilterApplyError(
+            f"Filter '{conf.get('name') or conf.get('id')}' requires a time "
+            "grain and cannot be cleared."
+        )
+    return {
+        "extraFormData": {"time_grain_sqla": time_grain[0]} if is_set else {},
+        "filterState": {"value": list(time_grain) if is_set else None},
+    }

Review Comment:
   **Suggestion:** `time_grain` is applied without checking the filter's 
configured `time_grains` allowlist, so a permalink can select a grain 
unavailable in that filter's frontend options.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Sometimes` ยท ๐Ÿท๏ธ `Api mismatch`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=5069d4aa9fec412bbb9543cda0ae049d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=5069d4aa9fec412bbb9543cda0ae049d&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/dashboard/tool/apply_dashboard_filters.py
   **Line:** 284:286
   **Comment:**
        *Api Mismatch: `time_grain` is applied without checking the filter's 
configured `time_grains` allowlist, so a permalink can select a grain 
unavailable in that filter's frontend options.
   
   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%2F44893&comment_hash=7b7261c9ef0b0b841426d99077629349ff20fc13e802c2beb1f97f077726ba77&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44893&comment_hash=7b7261c9ef0b0b841426d99077629349ff20fc13e802c2beb1f97f077726ba77&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/mcp_service/dashboard/tool/manage_native_filters.py:
##########
@@ -152,6 +177,37 @@ def _build_new_filter_config(
             "cascadeParentIds": [],
         }
 
+    if isinstance(spec, FilterRangeSpec):
+        _validate_dataset_column(spec.dataset_id, spec.column)

Review Comment:
   **Suggestion:** `filter_range` accepts any existing column, including 
strings, although the frontend only permits numeric columns; saved filters can 
therefore be invalid or query incorrectly.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Sometimes` ยท ๐Ÿท๏ธ `Type error`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=11efdc834cb344288176dc52118abc70&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=11efdc834cb344288176dc52118abc70&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/dashboard/tool/manage_native_filters.py
   **Line:** 180:181
   **Comment:**
        *Type Error: `filter_range` accepts any existing column, including 
strings, although the frontend only permits numeric columns; saved filters can 
therefore be invalid or query incorrectly.
   
   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%2F44893&comment_hash=08705315941a76ec9591e6cdfc74e611ffb5f3d1970f1d007e5b461eb31ed880&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44893&comment_hash=08705315941a76ec9591e6cdfc74e611ffb5f3d1970f1d007e5b461eb31ed880&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