Skip to content
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

Merged
merged 6 commits into from
Jul 11, 2024

Conversation

Vitor-Avila
Copy link
Contributor

@Vitor-Avila Vitor-Avila commented Jun 29, 2024

SUMMARY

#28570 updated SelectTagsValue and tagToSelectOption. 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 the tag.id as the value (rather than the tag.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 the SavedQueries API, for consistency with the Dashboard (#23909) and Chart (#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

  • Has associated issue:
  • Required feature flags: TAGGING_SYSTEM
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@github-actions github-actions bot added the api Related to the REST API label Jun 29, 2024
@dosubot dosubot bot added change:backend Requires changing the backend listview Namespace | Anything related to lists, such as Dashboards, Charts, Datasets, etc. need:tests This PR requires tests labels Jun 29, 2024
Copy link

codecov bot commented Jun 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.36%. Comparing base (76d897e) to head (dc78646).
Report is 966 commits behind head on master.

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     
Flag Coverage Δ
hive 49.15% <90.00%> (-0.02%) ⬇️
javascript 58.05% <ø> (+0.33%) ⬆️
mysql 77.01% <100.00%> (?)
postgres 77.12% <100.00%> (?)
presto 53.73% <90.00%> (-0.07%) ⬇️
python 83.68% <100.00%> (+20.19%) ⬆️
sqlite 76.60% <100.00%> (?)
unit 59.72% <100.00%> (+2.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


def apply(self, query: Query, value: Any) -> Query:
# ID based filter
if self.id_based_filter:
Copy link
Member

@hughhhh hughhhh Jul 2, 2024

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)

Copy link
Contributor Author

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 🙏

@Vitor-Avila Vitor-Avila requested a review from hughhhh July 8, 2024 19:53
Copy link
Member

@betodealmeida betodealmeida left a 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.

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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 🙏

@Vitor-Avila Vitor-Avila merged commit 33b934c into apache:master Jul 11, 2024
41 checks passed
@github-actions github-actions bot added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 4.1.0 labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the REST API 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels change:backend Requires changing the backend listview Namespace | Anything related to lists, such as Dashboards, Charts, Datasets, etc. need:tests This PR requires tests size/XL 🚢 4.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants