-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
v3.0.8
Feature type
Change to existing functionality
Proposed functionality
Custom validation was introduced in NetBox v3.0. To declare custom validation rules, an administrator must define the CUSTOM_VALIDATORS configuration parameter, mapping models to their validator classes like this:
CUSTOM_VALIDATORS = {
'dcim.site': (
CustomValidator({
'name': {
'min_length': 5,
'max_length': 30,
}
}),
)
}
This FR proposes support for two alternative methods of declaring custom validators (while preserving support for the approach above). First, it should be possible to pass a dictionary of rules directly in place of a CustomValidator instance. For example:
CUSTOM_VALIDATORS = {
'dcim.site': (
{
'name': {
'min_length': 5,
'max_length': 30,
}
},
)
}
The dictionary of rules will be passed when instantiating a CustomValidator instance. The second proposed alternative is to allow referencing by path a CustomValidator class defined elsewhere. For example:
CUSTOM_VALIDATORS = {
'dcim.site': (
'some_plugin.validators.MyCustomValidator',
)
}
Use case
Both approaches make it more convenient for users to write portable and repeatable custom validation rules, as they eliminate the need to handle any Python code directly.
Database changes
No response
External dependencies
No response