System page - Server Error if Custom Validation Logic is used #10122

Closed
opened 2025-12-29 21:27:09 +01:00 by adam · 0 comments
Owner

Originally created by @moseisleydk on GitHub (Aug 20, 2024).

Originally assigned to: @arthanson on GitHub.

Deployment Type

Self-hosted

NetBox Version

4.0.9

Python Version

3.11

Steps to Reproduce

This is also described at https://github.com/netbox-community/netbox/discussions/17214

If I in configuration.py add a custom validator like:

from extras.validators import CustomValidator

class UniqueSerial(CustomValidator):

    def validate(self, instance):
        from dcim.models import Device

        if instance.serial and Device.objects.exclude(pk=instance.pk).filter(serial=instance.serial).exists():
            self.fail("The Serial number already exists in NetBox", field='serial')

CUSTOM_VALIDATORS = {
    'dcim.device': (
        UniqueSerial(),
    )
}

the menu item "Sytem" at /core/system/ fails with:

Object of type UniqueSerial is not JSON serializable

Python version: 3.11.6
NetBox version: 4.0.9
Plugins:
netbox_secrets: 2.0.3
netbox_topology_views: 4.0.0

Expected Behavior

The page should be rendered correct and show system data.

Observed Behavior

If I remove

CUSTOM_VALIDATORS = { 'dcim.device': ( UniqueSerial(), ) }

from configuration.py, the page renders nicely

if seems to me that the page render tries to see UniqueSerial() as a json, and not code

Originally created by @moseisleydk on GitHub (Aug 20, 2024). Originally assigned to: @arthanson on GitHub. ### Deployment Type Self-hosted ### NetBox Version 4.0.9 ### Python Version 3.11 ### Steps to Reproduce This is also described at https://github.com/netbox-community/netbox/discussions/17214 If I in configuration.py add a custom validator like: ``` from extras.validators import CustomValidator class UniqueSerial(CustomValidator): def validate(self, instance): from dcim.models import Device if instance.serial and Device.objects.exclude(pk=instance.pk).filter(serial=instance.serial).exists(): self.fail("The Serial number already exists in NetBox", field='serial') CUSTOM_VALIDATORS = { 'dcim.device': ( UniqueSerial(), ) } ``` the menu item "Sytem" at /core/system/ fails with: Object of type UniqueSerial is not JSON serializable Python version: 3.11.6 NetBox version: 4.0.9 Plugins: netbox_secrets: 2.0.3 netbox_topology_views: 4.0.0 ### Expected Behavior The page should be rendered correct and show system data. ### Observed Behavior If I remove `CUSTOM_VALIDATORS = { 'dcim.device': ( UniqueSerial(), ) }` from configuration.py, the page renders nicely if seems to me that the page render tries to see UniqueSerial() as a json, and not code
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 21:27:09 +01:00
adam closed this issue 2025-12-29 21:27:09 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10122