-
Notifications
You must be signed in to change notification settings - Fork 300
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
Labels
type: bug
Something isn't working as expected
Comments
@joewesch What's the use case for bulk-deleting custom fields? |
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
pushed a commit
that referenced
this issue
Jul 14, 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Environment
Steps to Reproduce
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 callsQuerySet.delete()
.There is a caveat of
QuerySet.delete()
from the documentation: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 theCustomField.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 apost_delete
signal that can be used to run the custom delete actions instead.The text was updated successfully, but these errors were encountered: