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

10781 Directs graph.delete_instances to call bulk_delete methods #10782

Merged
merged 47 commits into from
May 4, 2024

Conversation

whatisgalen
Copy link
Member

@whatisgalen whatisgalen commented Apr 17, 2024

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Description of Change

This PR removes bespoke deletion logic for Graph.delete_instances() and instead has it call the appropriate methods from BulkDataDeleter. It also returns a count of deleted resources to the frontend.

Issues Solved

#10781

Checklist

  • Unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Ticket Background

Further comments

@whatisgalen whatisgalen changed the title 10781 show deleted instances ct 10781 show count of deleted resource instances in graph designer Apr 17, 2024
@jacobtylerwalls
Copy link
Member

delete_instances() does the very same count, wondering if it would be nice to just pass that back up? 🤔

@whatisgalen
Copy link
Member Author

delete_instances() does the very same count, wondering if it would be nice to just pass that back up? 🤔

Good call!

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Tested, works well. The message wasn't localized before, so we can worry about localization/pluralization at some other time.

Nice improvement. Thanks for being so responsive with the suggestions.

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Noticed a few things in the latest. Now that the scope is changing, I'd add a changelog and update the PR title. Thanks.

arches/app/etl_modules/bulk_data_deletion.py Outdated Show resolved Hide resolved
arches/app/models/graph.py Outdated Show resolved Hide resolved
arches/app/models/graph.py Outdated Show resolved Hide resolved
arches/app/etl_modules/bulk_data_deletion.py Outdated Show resolved Hide resolved
@@ -563,19 +563,18 @@ def delete(self):
)
)

def delete_instances(self, verbose=False):
def delete_instances(self, userid=None, verbose=False):
Copy link
Member

Choose a reason for hiding this comment

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

I make a habit of adding new optional arguments to the end of signatures to improve backwards compatibility.

Copy link
Member Author

Choose a reason for hiding this comment

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

If they're both kwargs does order still matter?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, unless they're keyword-only with *, to consume the positional args, which we don't have here. I floated starting to do this and got feedback that we don't do it anywhere else in Arches so not to bother with it.

Copy link
Member

Choose a reason for hiding this comment

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

@whatisgalen I don't plan on blocking a merge over it, but did you have further thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

in my humblest of opinions on kwarg order, userid makes more sense as an earlier argument since it's more important. I'm not married to it but would be great to merge this sooner rather than later

Copy link
Member

Choose a reason for hiding this comment

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

Agree that having verbose=False first is weird. I think arches-wide we should be open to the use of keyword-only arguments with * so that we don't end up introducing breaking changes like this. I'll consider writing a forum post.

In the meantime, I'll push a small breaking change notice to 7.6.0.md.

Copy link
Member

Choose a reason for hiding this comment

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

@whatisgalen whatisgalen changed the title 10781 show count of deleted resource instances in graph designer 10781 Directs graph.delete_instances to call bulk_delete methods Apr 22, 2024
Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Thanks for the test cleanup, they look great. ⭐

Heads up, I pushed two cleanup commits to your branch including the release note I mentioned, so you'll wanna pull.

Noticed a failure when performing a manual test:

  1. Graph Designer > Delete Associated Instances
2024-05-02 10:49:26   File "/web_root/arches/arches/app/views/graph.py", line 472, in delete
2024-05-02 10:49:26     resp = graph.delete_instances(userid=request.user.id)
2024-05-02 10:49:26   File "/web_root/arches/arches/app/models/graph.py", line 576, in delete_instances
2024-05-02 10:49:26     bulk_deleter.index_resource_deletion(loadid)
2024-05-02 10:49:26 TypeError: BulkDataDeletion.index_resource_deletion() missing 1 required positional argument: 'resourceids'

…archesproject/arches into 10781_show_deleted_instances_ct

merges latest changes on remote branch
@whatisgalen
Copy link
Member Author

whatisgalen commented May 3, 2024

Thanks for the test cleanup, they look great. ⭐

Heads up, I pushed two cleanup commits to your branch including the release note I mentioned, so you'll wanna pull.

Noticed a failure when performing a manual test:

  1. Graph Designer > Delete Associated Instances
2024-05-02 10:49:26   File "/web_root/arches/arches/app/views/graph.py", line 472, in delete
2024-05-02 10:49:26     resp = graph.delete_instances(userid=request.user.id)
2024-05-02 10:49:26   File "/web_root/arches/arches/app/models/graph.py", line 576, in delete_instances
2024-05-02 10:49:26     bulk_deleter.index_resource_deletion(loadid)
2024-05-02 10:49:26 TypeError: BulkDataDeletion.index_resource_deletion() missing 1 required positional argument: 'resourceids'

I neglected to refactor the signature for the bulk index method so that resourceids would be a kwarg defaulting to None. That change is in my latest commit.

bulk_deleter = BulkDataDeletion()
loadid = uuid.uuid4()
resp = bulk_deleter.delete_resources(userid, loadid, graphid=self.graphid, verbose=verbose)
bulk_deleter.index_resource_deletion(loadid)
Copy link
Member

@jacobtylerwalls jacobtylerwalls May 3, 2024

Choose a reason for hiding this comment

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

This will drive more traffic into #10872, but that's not something that needs to block this work. Just FYI.

@jacobtylerwalls
Copy link
Member

Taking a final look

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Thanks for the updates!

result["success"] = True
result["deleted_count"] = deleted_count
result["message"] = _("Successfully deleted {} resources").format(str(deleted_count))
Copy link
Member

Choose a reason for hiding this comment

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

I figure this is tolerable if there are 0 resources.
Screenshot 2024-05-03 at 11 00 51 AM

Comment on lines -136 to +139
if resourceids and graphid:
resources = Resource.objects.filter(graph_id=graphid).filter(pk__in=resourceids)
if resourceids:
resources = Resource.objects.filter(pk__in=resourceids)
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 this slightly degrades performance if both resources and graph are provided, so I don't see the readability tradeoff as worth it, but I don't see a current code path that exercises it, so I'm not too bothered.

@jacobtylerwalls jacobtylerwalls merged commit 3940c46 into dev/7.6.x May 4, 2024
6 checks passed
@jacobtylerwalls jacobtylerwalls deleted the 10781_show_deleted_instances_ct branch May 4, 2024 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Graph Designer: Deleting Associated Instances should tell you how many were deleted
4 participants