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

chore(command): Condense delete/bulk-delete operations #24607

Merged

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Jul 6, 2023

SUMMARY

This a a fast follow to #24466 which condensed the delete/bulk-delete DAO operations. Specifically it condenses the delete/bulk-delete commands into a single operation which helps to ensure we adhere to the DRY principle (and removes ~ 500 lines of code).

Though the change maybe somewhat difficult to grok from a GitHub diff perspective the logic is as follows. If there exists commands/bulk_delete.py and optionally commands/delete.py file, then:

  1. Delete the commands/delete.py file.
  2. Rename commands/bulk_delete.py to commands/delete.py.
  3. Rename BulkDelete... to Delete... for commands, exceptions, etc.

Note that delete DAOs currently support either one or a list of models (a feature added in #24466) whereas the commands currently only support a list. Ideally this should be more consistent, but I didn't want to go down the yak shaving route as there likely is more cleanup needed when the commands are refactored as the current validation logic (which mutates state) likely needs to be addressed.

Finally I didn't update the unit tests. The single and bulk deletion tests are still separate.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

CI.

ADDITIONAL INFORMATION

  • Has associated issue: [SIP-92] Proposal for restructuring the Python code base #20630
  • 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 john-bodley marked this pull request as ready for review July 6, 2023 18:18
@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Merging #24607 (a0669d4) into master (767afef) will decrease coverage by 0.07%.
The diff coverage is 91.22%.

❗ Current head a0669d4 differs from pull request most recent head 8d64ce9. Consider uploading reports for the commit 8d64ce9 to get more accurate results

@@            Coverage Diff             @@
##           master   #24607      +/-   ##
==========================================
- Coverage   69.03%   68.97%   -0.07%     
==========================================
  Files        1908     1902       -6     
  Lines       74210    74007     -203     
  Branches     8186     8186              
==========================================
- Hits        51232    51047     -185     
+ Misses      20857    20839      -18     
  Partials     2121     2121              
Flag Coverage Δ
hive 54.12% <21.92%> (+<0.01%) ⬆️
mysql 79.35% <91.22%> (-0.07%) ⬇️
postgres 79.44% <91.22%> (-0.07%) ⬇️
presto 54.02% <21.92%> (+<0.01%) ⬆️
python 83.45% <91.22%> (-0.05%) ⬇️
sqlite 78.03% <78.94%> (-0.05%) ⬇️
unit 54.84% <21.92%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
superset/reports/commands/exceptions.py 98.33% <ø> (-0.03%) ⬇️
superset/annotation_layers/api.py 86.20% <50.00%> (-0.12%) ⬇️
superset/css_templates/commands/delete.py 87.50% <50.00%> (ø)
superset/queries/saved_queries/commands/delete.py 87.50% <50.00%> (ø)
superset/row_level_security/commands/delete.py 86.36% <50.00%> (ø)
superset/annotation_layers/annotations/api.py 89.23% <66.66%> (-0.09%) ⬇️
superset/css_templates/api.py 95.74% <66.66%> (ø)
superset/datasets/api.py 88.62% <66.66%> (-0.04%) ⬇️
superset/queries/saved_queries/api.py 92.37% <66.66%> (ø)
superset/reports/api.py 90.22% <66.66%> (-0.08%) ⬇️
... and 17 more

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@john-bodley john-bodley force-pushed the john-bodley--command-bulk-delete branch 2 times, most recently from 5590729 to 655242f Compare July 6, 2023 21:03
@@ -68,5 +64,5 @@ class AnnotationUpdateFailedError(CreateFailedError):
message = _("Annotation could not be updated.")


class AnnotationDeleteFailedError(CommandException):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This illustrates a great example of the benefits of condensing logic. The bulk exceptions:

  1. Is subclassed from DeleteFailedError
  2. Uses language of the form Annotations could not be deleted.

whereas the non-bulk exceptions:

  1. Is subclassed from CommandException.
  2. Uses language of the form Annotation delete failed.

Here the legacy bulk logic seems more correct in terms of consistency with how create, update, etc. exceptions are defined.

class AnnotationDeleteFailedError(CommandException):
message = _("Annotation delete failed.")
class AnnotationDeleteFailedError(DeleteFailedError):
message = _("Annotations could not be deleted.")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than chart(s), query(ies), or query/queries I opted for—per a Google Search suggestion—always using the plural form for consistency.

@john-bodley john-bodley force-pushed the john-bodley--command-bulk-delete branch 2 times, most recently from e73fd1b to a53c1e2 Compare July 7, 2023 00:09

try:
DatasetDAO.delete(self._models)
except DeleteFailedError as ex:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was another positive byproduct of the change. Here we're catching a DeleteFailedError whereas in the non-bulk we were catching a DAODeleteFailedError error. The later is more accurate as it's a DAO rather than command failure.

@john-bodley john-bodley force-pushed the john-bodley--command-bulk-delete branch from a53c1e2 to fd66f43 Compare July 7, 2023 00:18
@john-bodley john-bodley changed the title chore(command): [WIP] Condense delete/bulk-delete operations chore(command): Condense delete/bulk-delete operations Jul 7, 2023
Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for the improvements @john-bodley. I left some non-blocking comments.

superset/dashboards/commands/exceptions.py Outdated Show resolved Hide resolved
superset/css_templates/commands/exceptions.py Outdated Show resolved Hide resolved
superset/row_level_security/commands/exceptions.py Outdated Show resolved Hide resolved
john-bodley and others added 5 commits July 12, 2023 14:00
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
@john-bodley john-bodley merged commit a156816 into apache:master Jul 12, 2023
@john-bodley john-bodley deleted the john-bodley--command-bulk-delete branch July 12, 2023 22:45
@michael-s-molina michael-s-molina added the v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch label Jul 13, 2023
michael-s-molina pushed a commit that referenced this pull request Jul 26, 2023
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
(cherry picked from commit a156816)
@mistercrunch mistercrunch added 🍒 3.0.4 🏷️ 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: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
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/XL v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch 🍒 3.0.0 🍒 3.0.1 🍒 3.0.2 🍒 3.0.3 🍒 3.0.4 🚢 3.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants