Skip to content

Enable accessing related object attributes via dotted path when defining custom validation rules #15490

Closed
@jeremystretch

Description

@jeremystretch

NetBox version

v3.7.4

Feature type

New functionality

Proposed functionality

When defining custom validation rules as JSON, it is currently possible to access only direct attributes on an object. For example:

CUSTOM_VALIDATORS = {
    "dcim.site": [
        {
            "name": {
                "min_length": 5,
            }
        }
    ]
}

It is not possible to reference an attribute of a related object; this would require creating a CustomValidator subclass in Python with a custom validate() method as discussed here.

This issue proposes a mechanism for referencing attributes of related objects, identified by a dotted path. For example, the following would reference a the name of a site's assigned region:

CUSTOM_VALIDATORS = {
    "dcim.site": [
        {
            "region.name": {
                "eq": "North Carolina",
            }
        }
    ]
}

This could be achieved by employing Python's operator.attrgetter() utility.

Use case

This enhancement will allow users to reach "deeper" into an object when validating it without the need to write a custom subclass in Python.

Database changes

None

External dependencies

None

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: featureIntroduction of new functionality to the application

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions