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

Custom fields don't fully delete when using bulk delete #1937

Closed
joewesch opened this issue Jun 21, 2022 · 2 comments · Fixed by #2043
Closed

Custom fields don't fully delete when using bulk delete #1937

joewesch opened this issue Jun 21, 2022 · 2 comments · Fixed by #2043
Assignees
Labels
type: bug Something isn't working as expected

Comments

@joewesch
Copy link
Contributor

Environment

  • Python version: 3.7.13
  • Nautobot version: 1.3.7b1

Steps to Reproduce

  1. Create a custom field on a Device
  2. Bulk delete the custom field

Expected Behavior

The CustomField object gets removed, but Device._custom_field_data still shows the custom field. It also shows up via GraphQL query.

Observed Behavior

The custom field should be removed from Device.

Analysis

When you delete an individual object in Nautobot, the ObjectDeleteView calls the .delete() method for that object. When you do a bulk delete, however, the BulkDeleteView creates a QuerySet of the items and calls QuerySet.delete().

There is a caveat of QuerySet.delete() from the documentation:

The delete() method does a bulk delete and does not call any delete() methods on your models.

In the case of CustomField there is a custom .delete() method that creates a Celery task to iterate through all of the objects that have that custom field and remove them accordingly. Since the CustomField.delete() method is not getting called, it is not cleaning the custom fields off of the related models. This is evident via the ORM or GraphQL.

In addition to CustomField, DeviceType also has a custom delete method, so they would also be susceptible to this same problem where the custom delete methods will not be called during the bulk delete.

Possible fixes

According to the documentation the QuerySet.delete() still emits a post_delete signal that can be used to run the custom delete actions instead.

@glennmatthews glennmatthews added the type: bug Something isn't working as expected label Jun 21, 2022
@glennmatthews glennmatthews moved this to To Groom in Nautobot Core ⚙️ Jun 21, 2022
@bryanculver
Copy link
Member

@joewesch What's the use case for bulk-deleting custom fields?

@bryanculver bryanculver moved this from To Groom to Todo in Nautobot Core ⚙️ Jul 11, 2022
@joewesch
Copy link
Contributor Author

The use case I know of is when someone created multiple custom fields with dashes instead of underscores in the slugs. Since you can't edit a slug after creation they needed to delete the old custom fields and recreate them. Instead of going to each one individually and deleting them they did a bulk delete, which was easier/faster.

@HanlinMiao HanlinMiao linked a pull request Jul 13, 2022 that will close this issue
@bryanculver bryanculver moved this from Todo to In Review in Nautobot Core ⚙️ Jul 13, 2022
@jathanism jathanism moved this from In Review to Reviewer Approved in Nautobot Core ⚙️ Jul 21, 2022
Repository owner moved this from Reviewer Approved to Done in Nautobot Core ⚙️ Jul 23, 2022
HanlinMiao pushed a commit that referenced this issue Jul 23, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants