When adding a Custom Field via API it does not accept null values for non-required fields in version 3.7.0 #9082

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

Originally created by @ariandres on GitHub (Jan 12, 2024).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

v3.7.0

Python Version

3.8

Steps to Reproduce

  1. An error is generated when a request is sent to create a Custom Field
curl -X 'POST' \
  'http://0.0.0.0/api/extras/custom-fields/' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'X-CSRFTOKEN: zM1Spw2GkaObXREv7mZHEvlIXdN7oG2sb8dGpmtta8x34hvg1Hjqnzwn24MqYOCR' \
  -d '{
  "content_types": [
    "dcim.rearport"
  ],
  "type": "text",
  "object_type": null,
  "name": "Test",
  "label": "string",
  "group_name": "string",
  "description": "string",
  "required": true,
  "search_weight": 32767,
  "filter_logic": "disabled",
  "ui_visible": "always",
  "ui_editable": "yes",
  "is_cloneable": true,
  "default": "string",
  "weight": 32767,
  "validation_minimum": null,
  "validation_maximum": null,
  "validation_regex": "string",
  "choice_set": null
}'

Expected Behavior

Add the Custom Field as defined.

Observed Behavior

The following error occurs when the request is submitted:

Code: 400
Details: Error: Bad Request
Response body:

{
  "object_type": [
    "This field may not be null."
  ],
  "choice_set": [
    "This field may not be null."
  ]
}

If the fields are removed from the request the behavior is as expected, however it is not a solution since I do not directly control what is sent in the HTTP request and it would not allow passing the fields from a non-null value to a null one.

Adding an Custom Field via GUI is not a problem (only the required fields are filled)

Originally created by @ariandres on GitHub (Jan 12, 2024). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version v3.7.0 ### Python Version 3.8 ### Steps to Reproduce 1. An error is generated when a request is sent to create a Custom Field ``` curl -X 'POST' \ 'http://0.0.0.0/api/extras/custom-fields/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'X-CSRFTOKEN: zM1Spw2GkaObXREv7mZHEvlIXdN7oG2sb8dGpmtta8x34hvg1Hjqnzwn24MqYOCR' \ -d '{ "content_types": [ "dcim.rearport" ], "type": "text", "object_type": null, "name": "Test", "label": "string", "group_name": "string", "description": "string", "required": true, "search_weight": 32767, "filter_logic": "disabled", "ui_visible": "always", "ui_editable": "yes", "is_cloneable": true, "default": "string", "weight": 32767, "validation_minimum": null, "validation_maximum": null, "validation_regex": "string", "choice_set": null }' ``` ### Expected Behavior Add the Custom Field as defined. ### Observed Behavior The following error occurs when the request is submitted: Code: 400 Details: Error: Bad Request Response body: ``` { "object_type": [ "This field may not be null." ], "choice_set": [ "This field may not be null." ] } ``` If the fields are removed from the request the behavior is as expected, however it is not a solution since I do not directly control what is sent in the HTTP request and it would not allow passing the fields from a non-null value to a null one. Adding an Custom Field via GUI is not a problem (only the required fields are filled)
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 20:45:13 +01:00
adam closed this issue 2025-12-29 20:45:14 +01:00
Author
Owner

@ariandres commented on GitHub (Jan 12, 2024):

Field Choice Set has the same behavior with the "base_choices" field

@ariandres commented on GitHub (Jan 12, 2024): Field Choice Set has the same behavior with the "base_choices" field
Author
Owner

@ariandres commented on GitHub (Jan 16, 2024):

@jeremystretch Thank you very much, I think the commit does not take into account the last comment.
"Field Choice Set" has the same behavior with the "base_choices" field

@ariandres commented on GitHub (Jan 16, 2024): @jeremystretch Thank you very much, I think the commit does not take into account the last comment. "Field Choice Set" has the same behavior with the "base_choices" field
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9082