Deleting DeviceType with Component raises DeviceType.DoesNotExist exception #3150

Closed
opened 2025-12-29 18:26:07 +01:00 by adam · 3 comments
Owner

Originally created by @rodvand on GitHub (Jan 13, 2020).

Originally assigned to: @jeremystretch on GitHub.

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.

Originally created by @rodvand on GitHub (Jan 13, 2020). Originally assigned to: @jeremystretch on GitHub. <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.6.8 * NetBox version: 2.6.11 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a wrapper like pynetbox. --> ### 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 <!-- What did you expect to happen? --> ### Expected Behavior The Device Type to be deleted and being redirected to the Device Type list. <!-- What happened instead? --> ### 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.
adam added the type: bugstatus: accepted labels 2025-12-29 18:26:07 +01:00
adam closed this issue 2025-12-29 18:26:08 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 13, 2020):

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.

@jeremystretch commented on GitHub (Jan 13, 2020): 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.
Author
Owner

@hSaria commented on GitHub (Jan 13, 2020):

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

@hSaria commented on GitHub (Jan 13, 2020): By that, you're also referring to other instances of `ObjectChange`, right?
Author
Owner

@jeremystretch commented on GitHub (Jan 13, 2020):

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 commented on GitHub (Jan 13, 2020): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3150