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): fix clears delete on Tags Modal #25470

Merged
merged 13 commits into from
Oct 5, 2023

Conversation

hughhhh
Copy link
Member

@hughhhh hughhhh commented Sep 29, 2023

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

  • Has associated issue:
  • Required feature flags:
  • 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

@john-bodley
Copy link
Member

@hughhhh would you mind filling out the PR description.

@john-bodley john-bodley self-requested a review October 2, 2023 16:54
if not objects_to_tag:
tagged_objects_to_delete = current_tagged_objects
else:
tagged_objects_to_delete = current_tagged_objects - updated_tagged_objects
Copy link
Member

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

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 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.

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

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?

Copy link
Member Author

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

@hughhhh hughhhh force-pushed the tags-fix-clear-delete branch from ba65e3b to 7e1150b Compare October 2, 2023 21:18
if not objects_to_tag:
tagged_objects_to_delete = current_tagged_objects
else:
tagged_objects_to_delete = current_tagged_objects - updated_tagged_objects
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 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.

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):
Copy link
Member

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?

# 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 = []
Copy link
Member

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?

if self._description:
tag.description = self._description
if description := self._properties.get("description"):
tag.description = description
Copy link
Member

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?

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", []):
Copy link
Member

@eschutho eschutho Oct 3, 2023

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.

@pull-request-size pull-request-size bot added size/L and removed size/M labels Oct 3, 2023
Copy link
Member

@eschutho eschutho left a 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!

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.

Looks good, left a few suggestions.

Comment on lines +394 to +398
tagged_objects_to_delete = (
current_tagged_objects
if not objects_to_tag
else current_tagged_objects - updated_tagged_objects
)
Copy link
Member

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:

Suggested change
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

Copy link
Member Author

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

superset/tags/commands/create.py Outdated Show resolved Hide resolved
superset/tags/commands/create.py Outdated Show resolved Hide resolved
superset/tags/commands/create.py Outdated Show resolved Hide resolved
hughhhh and others added 3 commits October 5, 2023 12:41
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
@hughhhh hughhhh merged commit dcfebfc into apache:master Oct 5, 2023
@hughhhh hughhhh deleted the tags-fix-clear-delete branch October 5, 2023 17:37
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.1.0 labels Mar 8, 2024
vinothkumar66 pushed a commit to vinothkumar66/superset that referenced this pull request Nov 11, 2024
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 3.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants