Add custom validation functionality for the models' delete method #6923

Closed
opened 2025-12-29 19:46:46 +01:00 by adam · 12 comments
Owner

Originally created by @atownson on GitHub (Sep 1, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.3.1

Feature type

New functionality

Proposed functionality

NetBox's extensible custom validation is a very nice feature which allows users to inject their own business-specific logic into the models' create and update methods. I'm proposing to add the same functionality to the delete method.

Use case

Users would be able to add their own logic to ensure instantiated models are not unintentionally deleted or to better control cascading effects of a delete. One example use case would be to ensure no IP addresses are assigned to a device's or virtual machine's interfaces before deleting either the device/VM or one of its interfaces. In our deployment of NetBox we track a good bit of metadata associated with IP addresses (such as NATs, ICMP polling status, and monitoring flags) and typically assign already created IPs to interfaces rather than creating them when assigning them.

Database changes

None

External dependencies

None

Originally created by @atownson on GitHub (Sep 1, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.3.1 ### Feature type New functionality ### Proposed functionality NetBox's extensible custom validation is a very nice feature which allows users to inject their own business-specific logic into the models' create and update methods. I'm proposing to add the same functionality to the delete method. ### Use case Users would be able to add their own logic to ensure instantiated models are not unintentionally deleted or to better control cascading effects of a delete. One example use case would be to ensure no IP addresses are assigned to a device's or virtual machine's interfaces before deleting either the device/VM or one of its interfaces. In our deployment of NetBox we track a good bit of metadata associated with IP addresses (such as NATs, ICMP polling status, and monitoring flags) and typically assign already created IPs to interfaces rather than creating them when assigning them. ### Database changes None ### External dependencies None
adam added the status: acceptedtype: feature labels 2025-12-29 19:46:46 +01:00
adam closed this issue 2025-12-29 19:46:47 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 1, 2022):

Interesting idea. We could probably implement this by hooking into the pre_delete signal to run validation. But how should we differentiate save and deletion validation rules? (Presumably they're likely to be different.)

@jeremystretch commented on GitHub (Sep 1, 2022): Interesting idea. We could probably implement this by hooking into the `pre_delete` signal to run validation. But how should we differentiate save and deletion validation rules? (Presumably they're likely to be different.)
Author
Owner

@atownson commented on GitHub (Sep 1, 2022):

I would differentiate the two by their configuration parameter names based on their respective roles.
If you were to prioritize ease of migration, you might just add the configuration parameter DELETE_CUSTOM_VALIDATORS.
If you were to prioritize the intuitiveness of the parameter names, you might migrate CUSTOM_VALIDATORS to CREATE_CUSTOM_VALIDATORS and add DELETE_CUSTOM_VALIDATORS. And perhaps even assume CUSTOM_VALIDATORS means CREATE_CUSTOM_VALIDATORS for legacy configuration settings.
Just my thoughts.

@atownson commented on GitHub (Sep 1, 2022): I would differentiate the two by their configuration parameter names based on their respective roles. If you were to prioritize ease of migration, you might just add the configuration parameter ```DELETE_CUSTOM_VALIDATORS```. If you were to prioritize the intuitiveness of the parameter names, you might migrate ```CUSTOM_VALIDATORS``` to ```CREATE_CUSTOM_VALIDATORS``` and add ```DELETE_CUSTOM_VALIDATORS```. And perhaps even assume ```CUSTOM_VALIDATORS``` means ```CREATE_CUSTOM_VALIDATORS``` for legacy configuration settings. Just my thoughts.
Author
Owner

@jeremystretch commented on GitHub (Sep 1, 2022):

Maybe we call them something like "protection rules" instead, and just use the same configuration format that we do for validators.

@jeremystretch commented on GitHub (Sep 1, 2022): Maybe we call them something like "protection rules" instead, and just use the same configuration format that we do for validators.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 1, 2022):

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 (Nov 1, 2022): 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

@kkthxbye-code commented on GitHub (Nov 1, 2022):

I think this would be a good addition. Open to any contributors, otherwise I'll pick it up when I get time.

@kkthxbye-code commented on GitHub (Nov 1, 2022): I think this would be a good addition. Open to any contributors, otherwise I'll pick it up when I get time.
Author
Owner

@github-actions[bot] commented on GitHub (Jan 1, 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 (Jan 1, 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

@jeremystretch commented on GitHub (Jan 24, 2023):

I'm going to tag this as needs milestone; hopefully we can get to it in a future release.

@jeremystretch commented on GitHub (Jan 24, 2023): I'm going to tag this as `needs milestone`; hopefully we can get to it in a future release.
Author
Owner

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

Love this! This would be very handy for us so only devices in a certain status could be deleted (we've introduced Disposed in our life cycle).

@BarbarossaTM commented on GitHub (Apr 22, 2023): Love this! This would be very handy for us so only devices in a certain status could be deleted (we've introduced `Disposed` in our life cycle).
Author
Owner

@pv2b commented on GitHub (Sep 8, 2023):

Hi!

I'd be interested to volunteer on implementing this, it seems like a small, self-contained feature and straight-forward enough. But it's set as "needs milestone", I'm not sure what that means in the context of this project?

@pv2b commented on GitHub (Sep 8, 2023): Hi! I'd be interested to volunteer on implementing this, it seems like a small, self-contained feature and straight-forward enough. But it's set as "needs milestone", I'm not sure what that means in the context of this project?
Author
Owner

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

@pv2b I've just tagged this for the upcoming v3.7 release if you'd like to work on it. (Please base your work on the feature branch.)

@jeremystretch commented on GitHub (Oct 13, 2023): @pv2b I've just tagged this for the upcoming v3.7 release if you'd like to work on it. (Please base your work on the `feature` branch.)
Author
Owner

@pv2b commented on GitHub (Oct 25, 2023):

@pv2b I've just tagged this for the upcoming v3.7 release if you'd like to work on it. (Please base your work on the feature branch.)

I'll be happy to work on this, but I'd like to see some progress on my other PR's on this project for work on accepted bug fixes before I do. I don't want to add too much to the projects backlog of pull requests.

@pv2b commented on GitHub (Oct 25, 2023): > @pv2b I've just tagged this for the upcoming v3.7 release if you'd like to work on it. (Please base your work on the `feature` branch.) I'll be happy to work on this, but I'd like to see some progress on my other PR's on this project for work on accepted bug fixes before I do. I don't want to add too much to the projects backlog of pull requests.
Author
Owner

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

@pv2b I've already completed work on this, thanks though.

@jeremystretch commented on GitHub (Oct 25, 2023): @pv2b I've already completed work on this, thanks though.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6923