bito-code-review[bot] commented on PR #40774:
URL: https://github.com/apache/superset/pull/40774#issuecomment-4625109727

   <!-- Bito Reply -->
   The flagged issue is correct. The function `_find_chart_layout_item` assumes 
`position_json` is a dictionary and calls `.values()` on it. If `position_json` 
is a list (e.g., from malformed or legacy data), this will raise an 
`AttributeError` and cause a 500 error in the API.
   
   To resolve this, you should add a type guard to ensure `position_json` is a 
dictionary before calling `_find_chart_layout_item` or normalize it to an empty 
dictionary if it is not.
   
   Here is the corrected implementation for 
`superset/charts/data/dashboard_filter_context.py`:
   
   ```python
   def _is_filter_in_scope_for_chart(
       filter_config: dict[str, Any],
       chart_id: int,
       position_json: dict[str, Any],
   ) -> bool:
       # ... (existing code)
       
       # Normalize position_json to a dict if it is not one
       layout = position_json if isinstance(position_json, dict) else {}
   
       if chart_layout_item := _find_chart_layout_item(chart_id, layout):
           parents: list[str] = chart_layout_item.get("parents", [])
           return any(parent in root_path for parent in parents)
       # ... (rest of the function)
   ```
   
   I have checked the PR comments and there are no other pending review 
comments to address.
   
   **superset/charts/data/dashboard_filter_context.py**
   ```
   # Normalize position_json to a dict if it is not one
       layout = position_json if isinstance(position_json, dict) else {}
   
       if chart_layout_item := _find_chart_layout_item(chart_id, layout):
           parents: list[str] = chart_layout_item.get("parents", [])
           return any(parent in root_path for parent in parents)
   ```


-- 
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