-
Notifications
You must be signed in to change notification settings - Fork 14k
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
chore(command): Condense delete/bulk-delete operations #24607
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
5590729
to
655242f
Compare
@@ -68,5 +64,5 @@ class AnnotationUpdateFailedError(CreateFailedError): | |||
message = _("Annotation could not be updated.") | |||
|
|||
|
|||
class AnnotationDeleteFailedError(CommandException): |
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.
This illustrates a great example of the benefits of condensing logic. The bulk exceptions:
- Is subclassed from
DeleteFailedError
- Uses language of the form
Annotations could not be deleted.
whereas the non-bulk exceptions:
- Is subclassed from
CommandException
. - 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.") |
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.
Rather than chart(s)
, query(ies)
, or query/queries
I opted for—per a Google Search suggestion—always using the plural form for consistency.
e73fd1b
to
a53c1e2
Compare
|
||
try: | ||
DatasetDAO.delete(self._models) | ||
except DeleteFailedError as ex: |
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.
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.
a53c1e2
to
fd66f43
Compare
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.
LGTM. Thank you for the improvements @john-bodley. I left some non-blocking comments.
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>
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com> (cherry picked from commit a156816)
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
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 optionallycommands/delete.py
file, then:commands/delete.py
file.commands/bulk_delete.py
tocommands/delete.py
.BulkDelete...
toDelete...
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