Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replication fields broken in custom validation #11032

Closed
bluikko opened this issue Nov 28, 2022 · 2 comments · Fixed by #11698
Closed

Replication fields broken in custom validation #11032

bluikko opened this issue Nov 28, 2022 · 2 comments · Fixed by #11698
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@bluikko
Copy link
Contributor

bluikko commented Nov 28, 2022

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 #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 #10312.

@bluikko bluikko added the type: bug A confirmed report of unexpected behavior in the application label Nov 28, 2022
@kkthxbye-code
Copy link
Contributor

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 kkthxbye-code added the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label Nov 28, 2022
@arthanson arthanson self-assigned this Nov 28, 2022
@github-actions
Copy link
Contributor

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 github-actions bot added the pending closure Requires immediate attention to avoid being closed for inactivity label Jan 28, 2023
@kkthxbye-code kkthxbye-code removed the pending closure Requires immediate attention to avoid being closed for inactivity label Feb 8, 2023
@kkthxbye-code kkthxbye-code self-assigned this Feb 8, 2023
kkthxbye-code pushed a commit to kkthxbye-code/netbox that referenced this issue Feb 8, 2023
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Feb 8, 2023
jeremystretch pushed a commit that referenced this issue Feb 8, 2023
* Fixes #11032 - Replication fields broken in custom validation

* Use getattr instead of hasattr to make sure custom validation is triggered as normal

---------

Co-authored-by: kkthxbye-code <>
jeremystretch added a commit that referenced this issue Feb 8, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants