-
Notifications
You must be signed in to change notification settings - Fork 16.2k
fix(dashboard): add name property to filter_state GET endpoint #36262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix(dashboard): add name property to filter_state GET endpoint #36262
Conversation
- Extract name from filter state value's id field - Return both value and name in GET response - Add test cases for name property extraction - Update OpenAPI schema documentation Fixes apache#36053
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review Agent Run #47ce7a
Actionable Suggestions - 1
-
superset/commands/dashboard/filter_state/get.py - 1
- Type safety issue in JSON name extraction · Line 58-60
Additional Suggestions - 7
-
tests/integration_tests/dashboards/filter_state/api_tests.py - 3
-
Missing return type annotation function · Line 277-277Add return type annotation `-> None` to function `test_get_dashboard_filter_state_with_name`. Similar issues exist at lines 293 and 309.
Code suggestion
@@ -277,7 +277,7 @@ def test_get_dashboard_filter_state_with_name( test_client, login_as_admin, dashboard_id: int, admin_id: int -) -> None: +) -> None: -
Unused function argument in test · Line 278-278Remove unused parameter `login_as_admin` from function signature, or add a comment explaining why it's needed. Similar issue at line 294.
Code suggestion
@@ -277,8 +277,8 @@ def test_get_dashboard_filter_state_with_name( - test_client, login_as_admin, dashboard_id: int, admin_id: int, + test_client, dashboard_id: int, admin_id: int, ) -> None:
-
Trailing comma missing in parameters · Line 278-278Add trailing comma after `admin_id: int` parameter. Similar issue at line 294.
Code suggestion
@@ -277,8 +277,8 @@ def test_get_dashboard_filter_state_with_name( test_client, login_as_admin, dashboard_id: int, admin_id: int, ) -> None:
-
-
superset/commands/dashboard/filter_state/get.py - 4
-
Trailing comma missing in function parameters · Line 46-46Add a trailing comma after the `cmd_params: CommandParameters` parameter in the `get_with_name` method signature for consistency.
Code suggestion
@@ -45,2 +45,2 @@ - def get_with_name( - self, cmd_params: CommandParameters + def get_with_name( + self, cmd_params: CommandParameters,
-
Use PEP 604 union type syntax · Line 47-47Use `X | Y` syntax instead of `Optional[dict[str, Optional[str]]]` for the return type annotation. Multiple similar issues exist on lines 36, 47, and 56.
Code suggestion
@@ -45,3 +45,3 @@ def get_with_name( self, cmd_params: CommandParameters, - ) -> Optional[dict[str, Optional[str]]]: + ) -> dict[str, str | None] | None: -
Docstring formatting issues · Line 48-48Fix docstring formatting: add a blank line after the summary line and move the summary to the first line of the docstring.
Code suggestion
@@ -48,4 +48,5 @@ - """ - Get filter state value and extract name from the JSON value. - Returns a dict with 'value' and 'name' keys. - """
-
Use PEP 604 union type syntax · Line 56-56Use `str | None` instead of `Optional[str]` for the type annotation. Multiple similar issues exist on lines 36, 47, and 56.
Code suggestion
@@ -56,1 +56,1 @@ - name: Optional[str] = None + name: str | None = None
-
Review Details
-
Files reviewed - 3 · Commit Range:
56a52fd..56a52fd- superset/commands/dashboard/filter_state/get.py
- superset/dashboards/filter_state/api.py
- tests/integration_tests/dashboards/filter_state/api_tests.py
-
Files skipped - 0
-
Tools
- Whispers (Secret Scanner) - ✔︎ Successful
- Detect-secrets (Secret Scanner) - ✔︎ Successful
- MyPy (Static Code Analysis) - ✔︎ Successful
- Astral Ruff (Static Code Analysis) - ✔︎ Successful
Bito Usage Guide
Commands
Type the following command in the pull request comment and save the comment.
-
/review- Manually triggers a full AI review. -
/pause- Pauses automatic reviews on this pull request. -
/resume- Resumes automatic reviews. -
/resolve- Marks all Bito-posted review comments as resolved. -
/abort- Cancels all in-progress reviews.
Refer to the documentation for additional commands.
Configuration
This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at [email protected].
Documentation & Help
| value_dict = json_utils.loads(value) | ||
| # Extract the 'id' field from the JSON value as the name | ||
| name = value_dict.get("id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Code suggestion
Check the AI-generated fix before applying
| value_dict = json_utils.loads(value) | |
| # Extract the 'id' field from the JSON value as the name | |
| name = value_dict.get("id") | |
| 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 |
Code Review Run #47ce7a
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #36262 +/- ##
===========================================
+ Coverage 0 68.12% +68.12%
===========================================
Files 0 632 +632
Lines 0 46488 +46488
Branches 0 5039 +5039
===========================================
+ Hits 0 31671 +31671
- Misses 0 13553 +13553
- Partials 0 1264 +1264
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
SUMMARY
Adds
nameproperty to theGET /api/v1/dashboard/{pk}/filter_state/{key}endpoint response. Thenameis extracted from theidfield in the JSONvalue, making it easier for frontend code to identify filter states without parsing the JSON value.Problem:
The frontend needs to identify filter states by their name, but the current API only returns the raw
valuestring. This requires the frontend to parse the JSON string and extract theidfield every time, which is inefficient and error-prone.Solution:
Extend the GET endpoint to return both
valueandnameproperties, wherenameis automatically extracted from theidfield in the JSONvalue. This maintains backward compatibility while providing the convenience of direct access to the filter name.IMPLEMENTATION DETAILS
Files Changed:
superset/commands/dashboard/filter_state/get.pyget_with_name()method toGetFilterStateCommandidfield from JSONvalueand returns bothvalueandnameidfield, or non-JSON valuesNonefornamewhenidis not present (graceful degradation)superset/dashboards/filter_state/api.pyget()method to callget_with_name()instead ofget()namepropertytests/integration_tests/dashboards/filter_state/api_tests.pytest_get_dashboard_filter_state_with_name()- verifies name extraction whenidexiststest_get_dashboard_filter_state_without_id()- verifiesnameisNonewhenidmissingnameproperty is always present in responseKey Implementation Points:
superset.utils.jsonfor JSON parsing (notsimplejsondirectly)JSONDecodeError,AttributeError, andTypeErrorexceptions gracefullyname: nullwhen value doesn't contain anidfield (not an error condition)valuecontinues to workBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - API change only
Before:
{ "value": "{\"id\":\"NATIVE_FILTER_ID\",\"extraFormData\":{...}}" }After:
{ "value": "{\"id\":\"NATIVE_FILTER_ID\",\"extraFormData\":{...}}", "name": "NATIVE_FILTER_ID" }TESTING INSTRUCTIONS
Manual Testing:
Create a dashboard with native filters:
Apply a filter:
Test the GET endpoint:
/api/v1/dashboard/{id}/filter_statekeyfrom the response/api/v1/dashboard/{id}/filter_state/{key}Verify response:
valueandnamepropertiesnameshould match theidfield from the JSONvaluevaluedoesn't containid,nameshould benullBrowser Console Test:
Automated Tests:
Edge Cases Tested:
idfield →nameextracted correctlyidfield →nameisnullvalue→nameisnull(graceful handling)value→nameisnull(graceful handling)ADDITIONAL INFORMATION
Backward Compatibility:
valuecontinues to worknameproperty is additive, doesn't break existing consumersError Handling:
name: null)idfield (returnsname: null)Performance: