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

Prevent the deletion of interfaces which have children assigned #12135

Closed
MrPaulAR opened this issue Mar 31, 2023 · 7 comments
Closed

Prevent the deletion of interfaces which have children assigned #12135

MrPaulAR opened this issue Mar 31, 2023 · 7 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@MrPaulAR
Copy link

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 #9359 (comment) 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

@MrPaulAR MrPaulAR added the type: feature Introduction of new functionality to the application label Mar 31, 2023
@jeremystretch jeremystretch added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Apr 3, 2023
@jsenecal
Copy link
Contributor

jsenecal commented 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.

@BarbarossaTM
Copy link
Contributor

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

@jeremystretch
Copy link
Member

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.

@github-actions
Copy link

github-actions bot commented 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 github-actions bot added the pending closure Requires immediate attention to avoid being closed for inactivity label Aug 3, 2023
@jsenecal
Copy link
Contributor

jsenecal commented 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 jsenecal added status: needs milestone Awaiting prioritization for inclusion with a future NetBox release and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation pending closure Requires immediate attention to avoid being closed for inactivity labels Aug 3, 2023
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs milestone Awaiting prioritization for inclusion with a future NetBox release labels Oct 13, 2023
@jeremystretch jeremystretch added this to the v3.7 milestone Oct 13, 2023
@jeremystretch jeremystretch changed the title Remove Child Interface when Removing the Parent Prevent the deletion of interfaces which have children assigned Oct 18, 2023
@jeremystretch jeremystretch self-assigned this Oct 20, 2023
@kkthxbye-code
Copy link
Contributor

kkthxbye-code commented 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.

#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 #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?

@jeremystretch
Copy link
Member

@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 added a commit that referenced this issue Nov 1, 2023
* Closes #12135: Prevent the deletion of interfaces with children

* Change PROTECT to RESTRICT

* Extend handle_protectederror() to also handle RestrictedError

* Fix string translation

* Update migrations

* Support bulk removal of parent interfaces via UI if all children are included

* Add support for the bulk deletion of restricted objects via REST API
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 31, 2024
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: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

5 participants