Custom validator using Config revision doesn't work #6431

Closed
opened 2025-12-29 19:40:38 +01:00 by adam · 4 comments
Owner

Originally created by @goebelmeier on GitHub (May 2, 2022).

NetBox version

v3.2.2

Python version

3.8

Steps to Reproduce

  1. Click on Admin -> Config revisions -> Add
  2. Fill in {'ipam.prefix': [{'tenant': {'required': True}}]} inside Custom validators text box
  3. Click save

Expected Behavior

Custom validator is saved and tenant is a required field for IPAM prefixes, like it works when adding the same JSON into text config like:

CUSTOM_VALIDATORS = {
    "ipam.prefix": [
        {
            "tenant": {
                "required": True,
            }
        }
    ]
}

Observed Behavior

Saving fails with error: "Enter a valid JSON."
Screenshot 2022-05-02 at 12 05 38

Originally created by @goebelmeier on GitHub (May 2, 2022). ### NetBox version v3.2.2 ### Python version 3.8 ### Steps to Reproduce 1. Click on Admin -> Config revisions -> Add 2. Fill in `{'ipam.prefix': [{'tenant': {'required': True}}]}` inside Custom validators text box 3. Click save ### Expected Behavior Custom validator is saved and tenant is a required field for IPAM prefixes, like it works when adding the same JSON into text config like: ``` CUSTOM_VALIDATORS = { "ipam.prefix": [ { "tenant": { "required": True, } } ] } ``` ### Observed Behavior Saving fails with error: "Enter a valid JSON." <img width="813" alt="Screenshot 2022-05-02 at 12 05 38" src="https://user-images.githubusercontent.com/1710701/166218109-92b12b59-aa14-4c30-b768-b224c24b5c5b.png">
adam added the type: bug label 2025-12-29 19:40:38 +01:00
adam closed this issue 2025-12-29 19:40:38 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (May 2, 2022):

What you are inputting is not valid json.

True has to be changed to lowercase.

JSON does not allow single quotes, so you have to change them to double quotes.

The following works on my dev instance:

{"ipam.prefix": [{"tenant": {"required": true}}]}

like it works when adding the same JSON into text config like

What is in the config file is not JSON but a python dictionary.

@kkthxbye-code commented on GitHub (May 2, 2022): What you are inputting is not valid json. `True` has to be changed to lowercase. JSON does not allow single quotes, so you have to change them to double quotes. The following works on my dev instance: `{"ipam.prefix": [{"tenant": {"required": true}}]}` >like it works when adding the same JSON into text config like What is in the config file is not JSON but a python dictionary.
Author
Owner

@goebelmeier commented on GitHub (May 2, 2022):

Thank you @kkthxbye-code for pushing me into the right direction. So this might be a future request: Show the right JSON at the config revisions page, if this value is configured correct inside the config file, so you simply need to copy & paste it. This is how config revisions page is rendered, if there is a configured static value inside config file:

Screenshot 2022-05-02 at 12 35 57
@goebelmeier commented on GitHub (May 2, 2022): Thank you @kkthxbye-code for pushing me into the right direction. So this might be a future request: Show the right JSON at the config revisions page, if this value is configured correct inside the config file, so you simply need to copy & paste it. This is how config revisions page is rendered, if there is a configured static value inside config file: <img width="820" alt="Screenshot 2022-05-02 at 12 35 57" src="https://user-images.githubusercontent.com/1710701/166221667-3a76ffaf-e295-4c77-8c4d-c6b1196966ea.png">
Author
Owner

@goebelmeier commented on GitHub (May 2, 2022):

Same with "View configuration revision" after putting correct JSON, it is displayed in a different parsed way and you cannot copy and paste it:
{"ipam.prefix": [{"tenant": {"required": true}}]} gets converted into
{'ipam.prefix': [{'tenant': {'required': True}}]}

Screenshot 2022-05-02 at 12 44 25
@goebelmeier commented on GitHub (May 2, 2022): Same with "View configuration revision" after putting correct JSON, it is displayed in a different parsed way and you cannot copy and paste it: `{"ipam.prefix": [{"tenant": {"required": true}}]}` gets converted into `{'ipam.prefix': [{'tenant': {'required': True}}]}` <img width="458" alt="Screenshot 2022-05-02 at 12 44 25" src="https://user-images.githubusercontent.com/1710701/166222495-c2a7fb5f-5bcd-433a-a437-40253dadb6c8.png">
Author
Owner

@kkthxbye-code commented on GitHub (May 2, 2022):

Feel free to create a new feature request for that part. I'm not sure about the intention when Jeremy created it, so I can't really provide an authoritative answer as to whether or not it's a good idea to dump the saved value is json.

@kkthxbye-code commented on GitHub (May 2, 2022): Feel free to create a new feature request for that part. I'm not sure about the intention when Jeremy created it, so I can't really provide an authoritative answer as to whether or not it's a good idea to dump the saved value is json.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6431