-
Notifications
You must be signed in to change notification settings - Fork 14k
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
fix(Tags filter): Filter assets by tag ID #29412
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #29412 +/- ##
==========================================
+ Coverage 60.48% 70.36% +9.87%
==========================================
Files 1931 1970 +39
Lines 76236 78610 +2374
Branches 8568 8973 +405
==========================================
+ Hits 46114 55312 +9198
+ Misses 28017 21100 -6917
- Partials 2105 2198 +93
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
superset/views/base_api.py
Outdated
|
||
def apply(self, query: Query, value: Any) -> Query: | ||
# ID based filter | ||
if self.id_based_filter: |
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.
Can we write a small unit test to verify the query is properly writing the query we want?
I think something like this would be good for the base class
filtered_query = filter_.apply(query, None) |
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.
Hey @hughhhh -- just added unit tests for the BaseTagFilter
-- the ChartTagNameFilter
, ChartTagIdFilter
, DashboardTagNameFilter
, DashboardTagIdFilter
, SavedQueryTagNameFilter
and SavedQueryTagIdFilter
should have integration tests already 🙌
Let me know if you have any other concerns or feedback 🙏
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.
Nice! I left a recommendation about splitting the BaseTagFilter
class into two, if you think it's not a lot of additional work — it might make the code easier to follow.
superset/views/base_api.py
Outdated
@@ -180,8 +180,19 @@ class BaseTagFilter(BaseFilter): # pylint: disable=too-few-public-methods | |||
""" The Tag class_name to user """ | |||
model: type[Dashboard | Slice | SqllabQuery | SqlaTable] = Dashboard | |||
""" The SQLAlchemy model """ | |||
id_based_filter = False |
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.
I think it would be cleaner to define a new BaseTagIdFilter
, and rename this one to BaseTagNameFilter
, to prevent the check in apply
.
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.
that makes sense! I just pushed a new commit with this change. I also ended up moving these two filters to superset.tag.filters
as I believe it makes more sense -- let me know your thoughts 🙏
SUMMARY
#28570 updated
SelectTagsValue
andtagToSelectOption
. These were also used by the Tags filter in the CRUD views (dashboards, charts and saved queries), so these filters stopped working (as they're now configured to use thetag.id
as the value (rather than thetag.name
which is expected by the API filter).This PR introduces a new filter operator for these assets to be able to filter tags by ID. I decided not to update the existing filter (that filters by name) and instead create a new one, to avoid a breaking change in the API.
I also removed the
TAGGING_SYSTEM
FF check in theSavedQueries
API, for consistency with theDashboard
(#23909) andChart
(#24060) APIs.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before
Screen.Recording.2024-06-29.at.8.47.31.PM.mov
After
After.mov
TESTING INSTRUCTIONS
Added integration tests for both API filters.
ADDITIONAL INFORMATION
TAGGING_SYSTEM