bito-code-review[bot] commented on code in PR #36262:
URL: https://github.com/apache/superset/pull/36262#discussion_r2559268382
##########
superset/commands/dashboard/filter_state/get.py:
##########
@@ -40,3 +41,25 @@ def get(self, cmd_params: CommandParameters) ->
Optional[str]:
if entry and self._refresh_timeout:
cache_manager.filter_state_cache.set(key, entry)
return entry.get("value")
+
+ def get_with_name(
+ self, cmd_params: CommandParameters
+ ) -> Optional[dict[str, Optional[str]]]:
+ """
+ Get filter state value and extract name from the JSON value.
+ Returns a dict with 'value' and 'name' keys.
+ """
+ value = self.get(cmd_params)
+ if not value:
+ return None
+
+ name: Optional[str] = None
+ try:
+ value_dict = json_utils.loads(value)
+ # Extract the 'id' field from the JSON value as the name
+ name = value_dict.get("id")
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Type safety issue in JSON name extraction</b></div>
<div id="fix">
The new `get_with_name` method extracts the 'id' field from parsed JSON as
the 'name', but doesn't ensure it's a string, violating the `Optional[str]`
type hint. This could cause type errors downstream in
`superset/dashboards/filter_state/api.py` where `get_with_name` is called,
potentially leading to runtime failures when processing filter state data. Add
a type check to enforce string type safety.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
value_dict = json_utils.loads(value)
# Extract the 'id' field from the JSON value as the name
name = value_dict.get("id")
if not isinstance(name, str):
name = None
````
</div>
</details>
</div>
<small><i>Code Review Run <a
href=https://github.com/apache/superset/pull/36262#issuecomment-3574585710>#47ce7a</a></i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]