instance.xxx object is not being updated within CUSTOM_VALIDATORS only when using API calls (works from UI forms) #9987

Closed
opened 2025-12-29 21:25:19 +01:00 by adam · 3 comments
Owner

Originally created by @xcluysen-dstny on GitHub (Jul 16, 2024).

Deployment Type

Self-hosted

NetBox Version

v3.7.8

Python Version

3.10

Steps to Reproduce

  1. Create Custom Validation code :
CUSTOM_VALIDATORS = {
    'dcim.device': (
        dcimCheckDevice(),
    )
}

class dcimCheckDevice(CustomValidator):
    def validate(self, instance):
        instance.description = 'The description should be overwritten by the Custom Validator'
  1. Create a device from the UI, any description you use will be overwritten by the CV
  2. Create a device from an API call, the description you use on your API call will NOT be overwritten by the CV

Expected Behavior

In both case (UI/API), the description should be overwritten.

Observed Behavior

If using the UI, it works (description is overwritten), if using the API, it doesn't work (description set by API is not overwritten)

Originally created by @xcluysen-dstny on GitHub (Jul 16, 2024). ### Deployment Type Self-hosted ### NetBox Version v3.7.8 ### Python Version 3.10 ### Steps to Reproduce 1. Create Custom Validation code : ``` CUSTOM_VALIDATORS = { 'dcim.device': ( dcimCheckDevice(), ) } class dcimCheckDevice(CustomValidator): def validate(self, instance): instance.description = 'The description should be overwritten by the Custom Validator' ``` 2. Create a device from the UI, any description you use will be overwritten by the CV 3. Create a device from an API call, the description you use on your API call will NOT be overwritten by the CV ### Expected Behavior In both case (UI/API), the description should be overwritten. ### Observed Behavior If using the UI, it works (description is overwritten), if using the API, it doesn't work (description set by API is not overwritten)
adam closed this issue 2025-12-29 21:25:19 +01:00
Author
Owner

@xcluysen-dstny commented on GitHub (Jul 16, 2024):

I checked that using ipam.ipaddress model not dcim.device but I believe this is caused by the instance object being copied when using API creation (so I update the copy but not the original).

@xcluysen-dstny commented on GitHub (Jul 16, 2024): I checked that using ipam.ipaddress model not dcim.device but I believe this is caused by the instance object being copied when using API creation (so I update the copy but not the original).
Author
Owner

@arthanson commented on GitHub (Jul 18, 2024):

Closing this as not a bug - Custom Validators are for validating models, they should not be used for modifying object data and could have potential issues if doing so. If there is an issue with the validator not getting run, or incorrectly running then please open an issue for that.

@arthanson commented on GitHub (Jul 18, 2024): Closing this as not a bug - Custom Validators are for validating models, they should not be used for modifying object data and could have potential issues if doing so. If there is an issue with the validator not getting run, or incorrectly running then please open an issue for that.
Author
Owner

@xcluysen-dstny commented on GitHub (Jul 18, 2024):

Thank you for your quick answer. How can I modify object data before / after validation then ?

@xcluysen-dstny commented on GitHub (Jul 18, 2024): Thank you for your quick answer. How can I modify object data before / after validation then ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9987