Prevent the deletion of interfaces which have children assigned #7840

Closed
opened 2025-12-29 20:28:53 +01:00 by adam · 7 comments
Owner

Originally created by @MrPaulAR on GitHub (Mar 31, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.4.7

Feature type

Change to existing functionality

Proposed functionality

When a parent interface is removed the child interface remains. There was some discussion in https://github.com/netbox-community/netbox/issues/9359#issuecomment-1127706103 regarding this but I don't think it was ever implemented or an explicit decision to not add this feature.

Initial state
image

After deleting the parent interface
image

The same is true when deleting a module. The parent interface is remove but the child persists.

Use case

I'm sure there are exceptions but I would think the child interfaces should be removed whenever the parent is deleted.

Database changes

I'm not smart enough for this.

External dependencies

No response

Originally created by @MrPaulAR on GitHub (Mar 31, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.4.7 ### Feature type Change to existing functionality ### Proposed functionality When a parent interface is removed the child interface remains. There was some discussion in https://github.com/netbox-community/netbox/issues/9359#issuecomment-1127706103 regarding this but I don't think it was ever implemented or an explicit decision to not add this feature. Initial state ![image](https://user-images.githubusercontent.com/3765696/229233061-cacae47c-657e-4659-8d27-d6365afaf072.png) After deleting the parent interface ![image](https://user-images.githubusercontent.com/3765696/229233174-3f2b4ebf-0bfa-4ef3-b4a7-7fdc66b91714.png) The same is true when deleting a module. The parent interface is remove but the child persists. ### Use case I'm sure there are exceptions but I would think the child interfaces should be removed whenever the parent is deleted. ### Database changes I'm not smart enough for this. ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 20:28:53 +01:00
adam closed this issue 2025-12-29 20:28:53 +01:00
Author
Owner

@jsenecal commented on GitHub (Apr 5, 2023):

I propose that we change dcim/models/device_components.py#L485 to on_delete=models.CASCADE

And do the same for other similar cases.

@jsenecal commented on GitHub (Apr 5, 2023): I propose that we change [dcim/models/device_components.py#L485](https://github.com/netbox-community/netbox/blob/develop/netbox/dcim/models/device_components.py#L485) to `on_delete=models.CASCADE` And do the same for other similar cases.
Author
Owner

@BarbarossaTM commented on GitHub (Apr 22, 2023):

I like this and I think with a confirmation screen which shows all interfaces to be deleted this would be very handy to have.

@BarbarossaTM commented on GitHub (Apr 22, 2023): I like this and I think with a confirmation screen which shows all interfaces to be deleted this would be very handy to have.
Author
Owner

@jeremystretch commented on GitHub (May 4, 2023):

I have to disagree; this seems very dangerous IMO. If the concern is about leaving orphaned interfaces, I'd suggest changing the on_delete behavior to PROTECT, which will prevent the deletion of the parent interface until all its children have been removed. This ensures that all delete operations are explicit and intentional, mitigating against the unintentional deletion of related objects.

@jeremystretch commented on GitHub (May 4, 2023): I have to disagree; this seems very dangerous IMO. If the concern is about leaving orphaned interfaces, I'd suggest changing the `on_delete` behavior to `PROTECT`, which will prevent the deletion of the parent interface until all its children have been removed. This ensures that all delete operations are explicit and intentional, mitigating against the unintentional deletion of related objects.
Author
Owner

@github-actions[bot] commented on GitHub (Aug 3, 2023):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Aug 3, 2023): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@jsenecal commented on GitHub (Aug 3, 2023):

I'd suggest changing the on_delete behavior to PROTECT

I'm good with either, but I do think that the delete confirmation, which tells which other objects are about to be deleted would suffice UI wise. Is your concern more about API behavior @jeremystretch ?

@jsenecal commented on GitHub (Aug 3, 2023): > I'd suggest changing the `on_delete` behavior to `PROTECT` I'm good with either, but I do think that the delete confirmation, which tells which other objects are about to be deleted would suffice UI wise. Is your concern more about API behavior @jeremystretch ?
Author
Owner

@kkthxbye-code commented on GitHub (Oct 20, 2023):

@jsenecal

but I do think that the delete confirmation, which tells which other objects are about to be deleted would suffice UI wise.

I agree. Changing it to cascade in combination with this wonderful PR would be a much better solution.

https://github.com/netbox-community/netbox/pull/14089

If I'm understanding it correctly, the suggested solution would require one to go the the interfaces tab and delete all virtual interfaces before deleting an entire device or removing a module. This seems super tedious. Imagine having to remove an entire rack and you have to go to every single device to remove virtual interfaces.

Edit: Tested it out and it does indeed function that way. In PR https://github.com/netbox-community/netbox/pull/14091 you can delete a device if it doesn't have any virtual interfaces but not if it has any. Seems inconsitent and confusing. Why are child interfaces more important than parent interfaces when deleting an entire device?

@kkthxbye-code commented on GitHub (Oct 20, 2023): @jsenecal > but I do think that the delete confirmation, which tells which other objects are about to be deleted would suffice UI wise. I agree. Changing it to cascade in combination with this wonderful PR would be a much better solution. https://github.com/netbox-community/netbox/pull/14089 If I'm understanding it correctly, the suggested solution would require one to go the the interfaces tab and delete all virtual interfaces before deleting an entire device or removing a module. This seems super tedious. Imagine having to remove an entire rack and you have to go to every single device to remove virtual interfaces. Edit: Tested it out and it does indeed function that way. In PR https://github.com/netbox-community/netbox/pull/14091 you can delete a device if it doesn't have any virtual interfaces but not if it has any. Seems inconsitent and confusing. Why are child interfaces more important than parent interfaces when deleting an entire device?
Author
Owner

@jeremystretch commented on GitHub (Oct 20, 2023):

@kkthxbye-code as I note above, the issue with blindly cascading interface deletions is that it can result in inadvertent deletion of child interfaces, which the user might not even be aware exist. #13690 does not offer sufficient protection against this because it is limited to workflows within the user interface.

In PR #14091 you can delete a device if it doesn't have any virtual interfaces but not if it has any. Seems inconsitent and confusing. Why are child interfaces more important than parent interfaces when deleting an entire device?

That's great feedback. Could you comment on the PR itself please? I'm sure we can work around it to bypass the issue for device/VM deletions.

@jeremystretch commented on GitHub (Oct 20, 2023): @kkthxbye-code as I note [above](https://github.com/netbox-community/netbox/issues/12135#issuecomment-1535315218), the issue with blindly cascading interface deletions is that it can result in inadvertent deletion of child interfaces, which the user might not even be aware exist. #13690 does not offer sufficient protection against this because it is limited to workflows within the user interface. > In PR #14091 you can delete a device if it doesn't have any virtual interfaces but not if it has any. Seems inconsitent and confusing. Why are child interfaces more important than parent interfaces when deleting an entire device? That's great feedback. Could you comment on the PR itself please? I'm sure we can work around it to bypass the issue for device/VM deletions.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7840