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


##########
superset/mcp_service/dashboard/schemas.py:
##########
@@ -1770,15 +1777,122 @@ def serialize_chart_summary(
     )
 
 
+def _native_filter_value_is_valid(filter_type: str, value: Any) -> bool:
+    """Validate display-value shapes without interpreting them as 
predicates."""
+    if value is None:
+        return True
+    if filter_type == "filter_time":
+        return isinstance(value, str)
+    if filter_type == "filter_range":
+        return (
+            isinstance(value, list)
+            and len(value) == 2
+            and all(
+                item is None
+                or (isinstance(item, (int, float)) and not isinstance(item, 
bool))
+                for item in value
+            )
+        )
+    if filter_type == "filter_timegrain":
+        return (
+            isinstance(value, list)
+            and len(value) <= 1
+            and all(isinstance(item, str) for item in value)
+        )
+    # Select values may be JSON scalars or flat scalar lists, never nested 
metadata.
+    values = value if isinstance(value, list) else [value]
+    return all(
+        item is None or isinstance(item, (str, int, float, bool)) for item in 
values
+    )
+
+
 def redact_filter_state_data_model_metadata(
     filter_state: Dict[str, Any],
+    native_filters: list[NativeFilterSummary] | None = None,
 ) -> Dict[str, Any]:
-    """Remove permalink filter state fields that expose data-model metadata."""
-    return {
+    """Hide raw metadata, retaining known native filters' display values.
+
+    Match IDs and types against dashboard configuration, not caller-supplied
+    mask metadata. Time-column and custom filters can carry column names even
+    in their value or label, and therefore are not projected.
+    """
+    result = {
         key: value
         for key, value in filter_state.items()
-        if key not in {"dataMask", "chartStates"}
+        if key
+        not in {
+            "dataMask",
+            "chartStates",
+            "native_filter_values",
+            "native_filter_values_incomplete",
+        }
     }
+    if native_filters is None or not (
+        {"dataMask", "chartStates"} & filter_state.keys()
+    ):
+        return result
+
+    summaries: list[dict[str, Any]] = []
+    mask = filter_state.get("dataMask", {})
+    incomplete = bool(filter_state.get("chartStates")) or not isinstance(mask, 
dict)
+    known_filters = {item.id: item for item in native_filters}
+    for filter_id, entry in mask.items() if isinstance(mask, dict) else []:
+        native_filter = known_filters.get(filter_id)
+        if (
+            native_filter is None
+            or native_filter.filter_type
+            not in {
+                "filter_select",
+                "filter_range",
+                "filter_time",
+                "filter_timegrain",
+            }
+            or not isinstance(entry, dict)
+            or not isinstance(entry.get("filterState"), dict)
+            or "value" not in entry["filterState"]
+        ):
+            incomplete = True
+            continue
+        extra = entry.get("extraFormData", {})
+        # Filter IDs survive type changes. A saved time-column mask can contain
+        # column names even when the dashboard config describes a supported 
type.
+        if not isinstance(extra, dict) or "granularity_sqla" in extra:
+            incomplete = True
+            continue

Review Comment:
   **Suggestion:** An active mask entry with empty `extraFormData` means the 
filter was cleared, but this still emits its `filterState.value` as a complete 
selection. [incorrect condition logic]
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Sometimes`
   
   [![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=f70bdb6c931c4c71b66144590dd66526&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=f70bdb6c931c4c71b66144590dd66526&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/schemas.py
   **Line:** 1856:1861
   **Comment:**
        *Incorrect Condition Logic: An active mask entry with empty 
`extraFormData` means the filter was cleared, but this still emits its 
`filterState.value` as a complete selection.
   
   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%2F44107&comment_hash=03846011108d0ddab0b6162e7e673adfe0c0cb6d7ad2989609f4e20cc86bac5b&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44107&comment_hash=03846011108d0ddab0b6162e7e673adfe0c0cb6d7ad2989609f4e20cc86bac5b&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/mcp_service/dashboard/schemas.py:
##########
@@ -1770,15 +1777,122 @@ def serialize_chart_summary(
     )
 
 
+def _native_filter_value_is_valid(filter_type: str, value: Any) -> bool:
+    """Validate display-value shapes without interpreting them as 
predicates."""
+    if value is None:
+        return True
+    if filter_type == "filter_time":
+        return isinstance(value, str)
+    if filter_type == "filter_range":
+        return (
+            isinstance(value, list)
+            and len(value) == 2
+            and all(
+                item is None
+                or (isinstance(item, (int, float)) and not isinstance(item, 
bool))
+                for item in value
+            )
+        )
+    if filter_type == "filter_timegrain":
+        return (
+            isinstance(value, list)
+            and len(value) <= 1
+            and all(isinstance(item, str) for item in value)
+        )
+    # Select values may be JSON scalars or flat scalar lists, never nested 
metadata.
+    values = value if isinstance(value, list) else [value]
+    return all(
+        item is None or isinstance(item, (str, int, float, bool)) for item in 
values
+    )
+
+
 def redact_filter_state_data_model_metadata(
     filter_state: Dict[str, Any],
+    native_filters: list[NativeFilterSummary] | None = None,
 ) -> Dict[str, Any]:
-    """Remove permalink filter state fields that expose data-model metadata."""
-    return {
+    """Hide raw metadata, retaining known native filters' display values.
+
+    Match IDs and types against dashboard configuration, not caller-supplied
+    mask metadata. Time-column and custom filters can carry column names even
+    in their value or label, and therefore are not projected.
+    """
+    result = {
         key: value
         for key, value in filter_state.items()
-        if key not in {"dataMask", "chartStates"}
+        if key
+        not in {
+            "dataMask",
+            "chartStates",
+            "native_filter_values",
+            "native_filter_values_incomplete",
+        }
     }
+    if native_filters is None or not (
+        {"dataMask", "chartStates"} & filter_state.keys()
+    ):
+        return result
+
+    summaries: list[dict[str, Any]] = []
+    mask = filter_state.get("dataMask", {})
+    incomplete = bool(filter_state.get("chartStates")) or not isinstance(mask, 
dict)
+    known_filters = {item.id: item for item in native_filters}
+    for filter_id, entry in mask.items() if isinstance(mask, dict) else []:
+        native_filter = known_filters.get(filter_id)
+        if (
+            native_filter is None
+            or native_filter.filter_type
+            not in {
+                "filter_select",
+                "filter_range",
+                "filter_time",
+                "filter_timegrain",
+            }
+            or not isinstance(entry, dict)
+            or not isinstance(entry.get("filterState"), dict)
+            or "value" not in entry["filterState"]
+        ):
+            incomplete = True
+            continue
+        extra = entry.get("extraFormData", {})
+        # Filter IDs survive type changes. A saved time-column mask can contain
+        # column names even when the dashboard config describes a supported 
type.
+        if not isinstance(extra, dict) or "granularity_sqla" in extra:
+            incomplete = True
+            continue
+        # A display value does not describe SQL predicates or wildcard
+        # matching. Signal that the summary cannot express these semantics.
+        predicates = extra.get("filters", [])
+        if extra.get("adhoc_filters") or (
+            native_filter.filter_type == "filter_select"
+            and (
+                not isinstance(predicates, list)
+                or any(
+                    not isinstance(predicate, dict)
+                    or predicate.get("op") not in ("IN", "NOT IN")
+                    for predicate in predicates
+                )
+            )
+        ):

Review Comment:
   **Suggestion:** Predicate checks only apply to select filters, so 
unsupported predicates on range or time filters are reported without marking 
the context incomplete. [incorrect condition logic]
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely`
   
   [![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=9a98f83d199749429c808b1ee1bea24c&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=9a98f83d199749429c808b1ee1bea24c&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/schemas.py
   **Line:** 1863:1875
   **Comment:**
        *Incorrect Condition Logic: Predicate checks only apply to select 
filters, so unsupported predicates on range or time filters are reported 
without marking the context incomplete.
   
   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%2F44107&comment_hash=44b7840f7dee688567f75621f63a5a883f0e51c6fa600dda44c9338c18f2554a&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44107&comment_hash=44b7840f7dee688567f75621f63a5a883f0e51c6fa600dda44c9338c18f2554a&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