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

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

Closed
peteeckel opened this issue Apr 7, 2024 · 5 comments
Assignees
Labels
beta Concerns a bug/feature in a beta release severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation topic: UI/UX User interface or user experience related work type: bug A confirmed report of unexpected behavior in the application

Comments

@peteeckel
Copy link
Contributor

peteeckel commented Apr 7, 2024

Deployment Type

Self-hosted

NetBox Version

v4.0-beta1 (commit c7f6c20)

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

@peteeckel peteeckel added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Apr 7, 2024
@peteeckel peteeckel changed the title Custom Validator does not show error message on object deletion PROTECT_RULE: Custom Validator does not show error message on object deletion Apr 7, 2024
@peteeckel peteeckel changed the title PROTECT_RULE: Custom Validator does not show error message on object deletion PROTECTION_RULES: Custom Validator does not show error message on object deletion Apr 7, 2024
@arthanson arthanson removed their assignment Apr 8, 2024
@arthanson
Copy link
Collaborator

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 arthanson self-assigned this Apr 8, 2024
@peteeckel
Copy link
Contributor Author

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(-)

@arthanson
Copy link
Collaborator

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 arthanson removed their assignment Apr 9, 2024
@arthanson arthanson added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available topic: UI/UX User interface or user experience related work and removed status: needs triage This issue is awaiting triage by a maintainer labels Apr 9, 2024
@Julio-Oliveira-Encora
Copy link
Contributor

Could you please assign it to me?

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation beta Concerns a bug/feature in a beta release and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Apr 15, 2024
@jeremystretch
Copy link
Member

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 up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beta Concerns a bug/feature in a beta release severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation topic: UI/UX User interface or user experience related work type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

4 participants