-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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): fix clears delete on Tags Modal #25470
Conversation
@hughhhh would you mind filling out the PR description. |
superset/daos/tag.py
Outdated
if not objects_to_tag: | ||
tagged_objects_to_delete = current_tagged_objects | ||
else: | ||
tagged_objects_to_delete = current_tagged_objects - updated_tagged_objects |
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.
maybe simplify with a ternary? Something like:
tagged_objects_to_delete = current_tagged_objects - updated_tagged_objects if objects_to_tag else current_tagged_objects
just slightly easier to read imo
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 you can replace all of this with:
tagged_objects_to_delete = current_tagged_objects - updated_tagged_objects
Since if objects_to_tag
is falsy then updated_tagged_objects
is an empty set.
superset/tags/schemas.py
Outdated
@@ -58,7 +58,7 @@ class TagObjectSchema(Schema): | |||
name = fields.String() | |||
description = fields.String(required=False, allow_none=True) | |||
objects_to_tag = fields.List( | |||
fields.Tuple((fields.String(), fields.Int())), required=False | |||
fields.Tuple((fields.String(), fields.Int())), |
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.
does this change the api? I know this is behind a feature flag, but in your opinion, is this a breaking change?
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.
good call out, this is a breaking change it's prolly safer to just keep as not required i've already have the proper .get() default value in place
ba65e3b
to
7e1150b
Compare
superset/daos/tag.py
Outdated
if not objects_to_tag: | ||
tagged_objects_to_delete = current_tagged_objects | ||
else: | ||
tagged_objects_to_delete = current_tagged_objects - updated_tagged_objects |
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 you can replace all of this with:
tagged_objects_to_delete = current_tagged_objects - updated_tagged_objects
Since if objects_to_tag
is falsy then updated_tagged_objects
is an empty set.
superset/tags/commands/create.py
Outdated
if self._objects_to_tag: | ||
if any(obj_id == 0 for obj_type, obj_id in self._objects_to_tag): | ||
if objects_to_tag := self._properties.get("objects_to_tag", []): | ||
if any(obj_id == 0 for obj_type, obj_id in objects_to_tag): |
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.
Why are we checking for id 0 here? Is this something that could happen realistically? Why not check for negative numbers, or integers — can we move this validation to the Marshmallow schema?
superset/tags/commands/create.py
Outdated
# Validate object type | ||
skipped_tagged_objects: list[tuple[str, int]] = [] | ||
for obj_type, obj_id in self._objects_to_tag: | ||
for obj_type, obj_id in objects_to_tag: | ||
skipped_tagged_objects = [] |
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.
why is skipped_tagged_objects defined twice, once above, and then again in this for loop?
superset/tags/commands/create.py
Outdated
if self._description: | ||
tag.description = self._description | ||
if description := self._properties.get("description"): | ||
tag.description = description |
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.
If we can use less "if" statements, like in here, I would suggest removing it, too. "If" statements IMO tend to break up the flow and make the code more difficult to read.
Can this be simplified to:
tag.description = self._properties.get("description")
would that change anything if self._properties.get("description")
is falsy?
superset/tags/commands/create.py
Outdated
if any(obj_id == 0 for obj_type, obj_id in self._objects_to_tag): | ||
exceptions.append(TagInvalidError()) | ||
|
||
if objects_to_tag := self._properties.get("objects_to_tag", []): |
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.
same here.. is this if statement necessary? If objects_to_tag is an empty array, then the for loop below will do nothing.
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.
Much easier to read now.. looks great!
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.
Looks good, left a few suggestions.
tagged_objects_to_delete = ( | ||
current_tagged_objects | ||
if not objects_to_tag | ||
else current_tagged_objects - updated_tagged_objects | ||
) |
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.
If objects_to_tag
is falsy then updated_tagged_objects
is an empty set, so this should work:
tagged_objects_to_delete = ( | |
current_tagged_objects | |
if not objects_to_tag | |
else current_tagged_objects - updated_tagged_objects | |
) | |
tagged_objects_to_delete = current_tagged_objects - updated_tagged_objects |
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.
so this logic won't work since updated tags includes both prev and new tags, so if we get a empty objects_to_tag
we the difference logic won't catch:
In [1]: current_tagged_object = [1, 2, 3]
In [2]: updated_tagged_object = [1]
In [3]: updated_tagged_object = [1, 4]
In [4]: current_tagged_object - updated_tagged_object
In [5]: set(current_tagged_object) - set(updated_tagged_object)
Out[5]: {2, 3}
In [6]: updated_tagged_object = []
In [7]: set(current_tagged_object) - set(updated_tagged_object)
Out[7]: {1, 2, 3} >> won't delete anything
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
SUMMARY
Currently the clear dropdown functionality doesn't work in production, this fix properly handles the logic to properly to untag certain entities
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Screen.Recording.2023-10-02.at.5.03.20.PM.mov
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION