Skip to content

Deleting DeviceType with Component raises DeviceType.DoesNotExist exception #3900

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

Closed
rodvand opened this issue Jan 13, 2020 · 3 comments
Closed
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@rodvand
Copy link
Contributor

rodvand commented Jan 13, 2020

Environment

  • Python version: 3.6.8
  • NetBox version: 2.6.11

Steps to Reproduce

  1. Create a Device Type
  2. Add any component to the device type template (example two Power ports)
  3. Delete the Device Type

Expected Behavior

The Device Type to be deleted and being redirected to the Device Type list.

Observed Behavior

The Device Type is deleted, but an exception is raised:

<class 'dcim.models.DeviceType.DoesNotExist'>

DeviceType matching query does not exist.

The URL with the exception is https://netbox-server/dcim/device-types/3/delete/

It seems like deleting the device type components are trying to redirect to the Device Type after deletion, but the Device Type has already been deleted. So some way of differentiating the return_url when deleting the Device Type (which includes deleting all components) contra when deleting only components from the Device Type is needed.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application labels Jan 13, 2020
@jeremystretch
Copy link
Member

The root issue here is that the component template(s) are being deleted after the parent device type. When NetBox attempts to record a changelog entry for the deletion of the component templates, an exception is raised because the parent DeviceType instance no longer exists. Other models in NetBox (e.g. devices) appear to be affected by this bug as well.

I'll need to take more time to dig into this. It's not sufficient to simply nullify the parent field as we need to ensure the relationship is recorded in the changelog.

@hSaria
Copy link
Contributor

hSaria commented Jan 13, 2020

By that, you're also referring to other instances of ObjectChange, right?

@jeremystretch
Copy link
Member

What I mean is that the ObjectChange that gets created in response to the deletion of a component template must be associated with the template's parent DeviceType.

This is assuming we continue recording ObjectChanges for related items during deletion events. I've been wondering lately if there's any real reason to do so. Omitting them would greatly speed up deletion actions where there are many related objects (e.g. deleting a device with hundreds of interfaces). That's a separate discussion though.

@jeremystretch jeremystretch self-assigned this Jan 13, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants