-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
Changes from 3 commits
db5b878
eb042c3
cf3e740
9b522cd
3975bf5
dc78646
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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 | ||||
|
||||
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 commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @hughhhh -- just added unit tests for the Let me know if you have any other concerns or feedback 🙏 |
||||
tags_query = ( | ||||
db.session.query(self.model.id) | ||||
.join(self.model.tags) | ||||
.filter(Tag.id == value) | ||||
) | ||||
return query.filter(self.model.id.in_(tags_query)) | ||||
|
||||
# Name based filter | ||||
ilike_value = f"%{value}%" | ||||
tags_query = ( | ||||
db.session.query(self.model.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.
I think it would be cleaner to define a new
BaseTagIdFilter
, and rename this one toBaseTagNameFilter
, to prevent the check inapply
.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 🙏