Custom Validators - Direct Class Reference is passing the validator incorrectly #6386

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

Originally created by @kkthxbye-code on GitHub (Apr 21, 2022).

Originally assigned to: @kkthxbye-code on GitHub.

Change Type

Correction

Area

Other

Proposed Changes

The example for Direct Class Reference currently looks like this.

from my_validators import Validator1, Validator2, Validator3

CUSTOM_VALIDATORS = {
    'dcim.site': (
        Validator1,
        Validator2,
    ),
    'dcim.device': (
        Validator3,
    )
}

When passing the uninitialized class, the code initializes it with the instance, which causes an error. It errors because it passes the instance to the constructor, which only expects a validation_rules dict.

d22f9000d6/netbox/extras/validators.py (L62-L64)

Suggested change:

from my_validators import Validator1, Validator2, Validator3

CUSTOM_VALIDATORS = {
    'dcim.site': (
        Validator1(),
        Validator2(),
    ),
    'dcim.device': (
        Validator3(),
    )
}
Originally created by @kkthxbye-code on GitHub (Apr 21, 2022). Originally assigned to: @kkthxbye-code on GitHub. ### Change Type Correction ### Area Other ### Proposed Changes The example for Direct Class Reference currently looks like this. ``` from my_validators import Validator1, Validator2, Validator3 CUSTOM_VALIDATORS = { 'dcim.site': ( Validator1, Validator2, ), 'dcim.device': ( Validator3, ) } ``` When passing the uninitialized class, the code initializes it with the instance, which causes an error. It errors because it passes the instance to the constructor, which only expects a `validation_rules` dict. https://github.com/netbox-community/netbox/blob/d22f9000d6ee103da81de5d8221ca4418be54a3a/netbox/extras/validators.py#L62-L64 Suggested change: ``` from my_validators import Validator1, Validator2, Validator3 CUSTOM_VALIDATORS = { 'dcim.site': ( Validator1(), Validator2(), ), 'dcim.device': ( Validator3(), ) } ```
adam added the status: acceptedtype: documentation labels 2025-12-29 19:40:06 +01:00
adam closed this issue 2025-12-29 19:40:06 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6386