PROTECTION_RULES: Custom Validator does not show error message on object deletion #9451

Closed
opened 2025-12-29 20:50:05 +01:00 by adam · 5 comments
Owner

Originally created by @peteeckel on GitHub (Apr 7, 2024).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.0-beta1 (commit c7f6c206cf)

Python Version

3.11

Steps to Reproduce

  1. Create a custom validator with the following code:
from extras.validators import CustomValidator
from utilities.exceptions import AbortRequest


class IPAddressDeleteValidator(CustomValidator):

    def validate(self, instance, request):
        raise AbortRequest("Do not delete IP addresses!")

and store as /opt/netbox/validators/test.py

  1. Add the custom validator as a protect rule for IPAddress objects:
PROTECTION_RULES = {
    "ipam.ipaddress": [
        "validators.test.IPAddressDeleteValidator",
    ]
}
  1. Navigate to IPAM/IP Addresses
  2. Create an arbitrary IP address
  3. Click on "Delete" in the new address's detail view and confirm deletion

Expected Behavior

The IP address is not deleted, an error message is shown saying "Do not delete IP addresses!"

Observed Behavior

The IP address is not deleted, but there is no error message.

The error message is, however, displayed when one tries to delete an IP address using the bulk edit view:

Untitled

Originally created by @peteeckel on GitHub (Apr 7, 2024). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.0-beta1 (commit c7f6c206cf5068f890b89da9ca04d4d3583f5107) ### Python Version 3.11 ### Steps to Reproduce 1. Create a custom validator with the following code: ```python from extras.validators import CustomValidator from utilities.exceptions import AbortRequest class IPAddressDeleteValidator(CustomValidator): def validate(self, instance, request): raise AbortRequest("Do not delete IP addresses!") ``` and store as `/opt/netbox/validators/test.py` 2. Add the custom validator as a protect rule for `IPAddress` objects: ```python PROTECTION_RULES = { "ipam.ipaddress": [ "validators.test.IPAddressDeleteValidator", ] } ``` 3. Navigate to IPAM/IP Addresses 4. Create an arbitrary IP address 5. Click on "Delete" in the new address's detail view and confirm deletion ### Expected Behavior The IP address is not deleted, an error message is shown saying "Do not delete IP addresses!" ### Observed Behavior The IP address is not deleted, but there is no error message. The error message is, however, displayed when one tries to delete an IP address using the bulk edit view: ![Untitled](https://github.com/netbox-community/netbox/assets/6815386/799c7aad-8d48-4b53-b776-dfd9582400b5)
adam added the type: bugstatus: acceptedbetatopic: UI/UXseverity: low labels 2025-12-29 20:50:05 +01:00
adam closed this issue 2025-12-29 20:50:05 +01:00
Author
Owner

@arthanson commented on GitHub (Apr 8, 2024):

Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v4.0-beta1. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data. See screenshot of it showing the error on detail-view delete:

Monosnap 172 16 0 7:24 | NetBox 2024-04-08 09-01-08

@arthanson commented on GitHub (Apr 8, 2024): Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v4.0-beta1. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data. See screenshot of it showing the error on detail-view delete: ![Monosnap 172 16 0 7:24 | NetBox 2024-04-08 09-01-08](https://github.com/netbox-community/netbox/assets/99642/5925af04-f8b8-4e2b-88ba-0689bcf53697)
Author
Owner

@peteeckel commented on GitHub (Apr 8, 2024):

Hi @arthanson, I amended the instructions for more clarity.

The fact that you are not able to reproduce it with the 4.0-beta1 was the right hint: The problem was introduced after the "stable" beta. I was able to bisect it:

(netbox) [root@dns netbox]# git bisect start 
status: waiting for both good and bad commits
(netbox) [root@dns netbox]# git bisect good 
status: waiting for bad commit, 1 good commit known
(netbox) [root@dns netbox]# git checkout feature 
Previous HEAD position was 8d773b1b9 Add warning to beta release notes
Switched to branch 'feature'
Your branch is up to date with 'origin/feature'.
(netbox) [root@dns netbox]# git bisect bad 
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[99fe63569dc5f2024a887b5eaf20efc534ceaeea] Fixes #15617: Fix rack elevation styling under dark mode
(netbox) [root@dns netbox]# systemctl restart netbox netbox-rq 
(netbox) [root@dns netbox]# git bisect good 
Bisecting: 1 revision left to test after this (roughly 1 step)
[d34f188d40b11d7d70d5d46cbc3f9accb2d876a8] Fixes #15637: Fix rendering of links from within embedded tables w/HTMX enabled (#15642)
(netbox) [root@dns netbox]# systemctl restart netbox netbox-rq 
(netbox) [root@dns netbox]# git bisect bad 
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[ccca0580f7835387137e880f41f2a0eab0beb500] Fixes #15619: Enforce a minimum width for progress bars
(netbox) [root@dns netbox]# systemctl restart netbox netbox-rq 
(netbox) [root@dns netbox]# git bisect good 
d34f188d40b11d7d70d5d46cbc3f9accb2d876a8 is the first bad commit
commit d34f188d40b11d7d70d5d46cbc3f9accb2d876a8
Author: Jeremy Stretch <jstretch@netboxlabs.com>
Date:   Fri Apr 5 14:22:09 2024 -0400

    Fixes #15637: Fix rendering of links from within embedded tables w/HTMX enabled (#15642)
    
    * Add htmx_table to __all__
    
    * Fix dropdown menu clipping
    
    * Fix loading links from within embedded tables
    
    * Fix rendering of object deletion warning

 netbox/netbox/views/generic/object_views.py         | 2 +-
 netbox/templates/generic/object_delete.html         | 2 +-
 netbox/templates/inc/table_htmx.html                | 3 +--
 netbox/utilities/htmx.py                            | 2 +-
 netbox/utilities/templates/builtins/htmx_table.html | 2 +-
 netbox/utilities/templatetags/builtins/tags.py      | 1 +
 6 files changed, 6 insertions(+), 6 deletions(-)
@peteeckel commented on GitHub (Apr 8, 2024): Hi @arthanson, I amended the instructions for more clarity. The fact that you are not able to reproduce it with the 4.0-beta1 was the right hint: The problem was introduced after the "stable" beta. I was able to bisect it: ```bash (netbox) [root@dns netbox]# git bisect start status: waiting for both good and bad commits (netbox) [root@dns netbox]# git bisect good status: waiting for bad commit, 1 good commit known (netbox) [root@dns netbox]# git checkout feature Previous HEAD position was 8d773b1b9 Add warning to beta release notes Switched to branch 'feature' Your branch is up to date with 'origin/feature'. (netbox) [root@dns netbox]# git bisect bad Bisecting: 3 revisions left to test after this (roughly 2 steps) [99fe63569dc5f2024a887b5eaf20efc534ceaeea] Fixes #15617: Fix rack elevation styling under dark mode (netbox) [root@dns netbox]# systemctl restart netbox netbox-rq (netbox) [root@dns netbox]# git bisect good Bisecting: 1 revision left to test after this (roughly 1 step) [d34f188d40b11d7d70d5d46cbc3f9accb2d876a8] Fixes #15637: Fix rendering of links from within embedded tables w/HTMX enabled (#15642) (netbox) [root@dns netbox]# systemctl restart netbox netbox-rq (netbox) [root@dns netbox]# git bisect bad Bisecting: 0 revisions left to test after this (roughly 0 steps) [ccca0580f7835387137e880f41f2a0eab0beb500] Fixes #15619: Enforce a minimum width for progress bars (netbox) [root@dns netbox]# systemctl restart netbox netbox-rq (netbox) [root@dns netbox]# git bisect good d34f188d40b11d7d70d5d46cbc3f9accb2d876a8 is the first bad commit commit d34f188d40b11d7d70d5d46cbc3f9accb2d876a8 Author: Jeremy Stretch <jstretch@netboxlabs.com> Date: Fri Apr 5 14:22:09 2024 -0400 Fixes #15637: Fix rendering of links from within embedded tables w/HTMX enabled (#15642) * Add htmx_table to __all__ * Fix dropdown menu clipping * Fix loading links from within embedded tables * Fix rendering of object deletion warning netbox/netbox/views/generic/object_views.py | 2 +- netbox/templates/generic/object_delete.html | 2 +- netbox/templates/inc/table_htmx.html | 3 +-- netbox/utilities/htmx.py | 2 +- netbox/utilities/templates/builtins/htmx_table.html | 2 +- netbox/utilities/templatetags/builtins/tags.py | 1 + 6 files changed, 6 insertions(+), 6 deletions(-) ```
Author
Owner

@arthanson commented on GitHub (Apr 9, 2024):

So it looks like it is getting run, but the message just flashes and goes away - if you look quickly you can spot it at the bottom.

@arthanson commented on GitHub (Apr 9, 2024): So it looks like it is getting run, but the message just flashes and goes away - if you look quickly you can spot it at the bottom.
Author
Owner

@Julio-Oliveira-Encora commented on GitHub (Apr 15, 2024):

Could you please assign it to me?

@Julio-Oliveira-Encora commented on GitHub (Apr 15, 2024): Could you please assign it to me?
Author
Owner

@jeremystretch commented on GitHub (Apr 15, 2024):

I suspect the embedded services table is causing the error toasts to be cleared out when it's loaded. If you remove it from the ipaddress.html template, the errors appear normally.

@jeremystretch commented on GitHub (Apr 15, 2024): I suspect the embedded services table is causing the error toasts to be cleared out when it's loaded. If you remove it from the `ipaddress.html` template, the errors appear normally.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9451