Replication fields broken in custom validation #7289

Closed
opened 2025-12-29 20:21:21 +01:00 by adam · 2 comments
Owner

Originally created by @bluikko on GitHub (Nov 28, 2022).

Originally assigned to: @kkthxbye-code on GitHub.

NetBox version

v3.3.8

Python version

3.9

Steps to Reproduce

After updating NetBox 3.2.x to 3.3.8 the custom validation logic that used to work is now broken.

  1. Create a custom validator that tries to validate a replication field, for example for VMInterface model try to validate field name.
  2. Try to add a new interface to a VM.

Expected Behavior

The custom validator should have access to name field.

Observed Behavior

The name field is always empty when creating a new object and the custom validation logic fails.

As per https://github.com/netbox-community/netbox/discussions/11031 this is apparently due to "replication fields (think interface name expansion) was refactored in that PR and seems to have caused the name field to be blank at the time of validation", possibly due to https://github.com/netbox-community/netbox/pull/10312.

Originally created by @bluikko on GitHub (Nov 28, 2022). Originally assigned to: @kkthxbye-code on GitHub. ### NetBox version v3.3.8 ### Python version 3.9 ### Steps to Reproduce After updating NetBox 3.2.x to 3.3.8 the custom validation logic that used to work is now broken. 1. Create a custom validator that tries to validate a replication field, for example for `VMInterface` model try to validate field `name`. 2. Try to add a new interface to a VM. ### Expected Behavior The custom validator should have access to `name` field. ### Observed Behavior The `name` field is always empty when creating a new object and the custom validation logic fails. As per https://github.com/netbox-community/netbox/discussions/11031 this is apparently due to "replication fields (think interface name expansion) was refactored in that PR and seems to have caused the name field to be blank at the time of validation", possibly due to https://github.com/netbox-community/netbox/pull/10312.
adam added the type: bugstatus: accepted labels 2025-12-29 20:21:21 +01:00
adam closed this issue 2025-12-29 20:21:22 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Nov 28, 2022):

Another side-effect of that change is that creating a duplicate interface (device or vm) fails silently instead of showing the form validation error. Before v3.3.3 it showed the also sub-optimal "This field is required" form validation error.

I'm guessing there's some order issues with how validation is executed.

Complete replication steps for posterity:

  • Create a site testsite
  • Create a virtual machine testvm
  • Register a custom validator in configuration.py (or wherever):
from extras.validators import CustomValidator

class MyValidator(CustomValidator):
    def validate(self, instance):
        self.fail(f"Name is: {instance.name}")

CUSTOM_VALIDATORS = {
    'virtualization.vminterface': (
        MyValidator(),
    )
}
  • Create an interface testinterface on vm testvm.
  • Notice that validation fails with error "Name is: " - indicating the the vminterface name is blank
@kkthxbye-code commented on GitHub (Nov 28, 2022): Another side-effect of that change is that creating a duplicate interface (device or vm) fails silently instead of showing the form validation error. Before v3.3.3 it showed the also sub-optimal "This field is required" form validation error. I'm guessing there's some order issues with how validation is executed. Complete replication steps for posterity: * Create a site `testsite` * Create a virtual machine `testvm` * Register a custom validator in configuration.py (or wherever): ``` from extras.validators import CustomValidator class MyValidator(CustomValidator): def validate(self, instance): self.fail(f"Name is: {instance.name}") CUSTOM_VALIDATORS = { 'virtualization.vminterface': ( MyValidator(), ) } ``` * Create an interface `testinterface` on vm `testvm`. * Notice that validation fails with error "Name is: " - indicating the the vminterface name is blank
Author
Owner

@github-actions[bot] commented on GitHub (Jan 28, 2023):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Jan 28, 2023): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7289