Custom Field Defaults are handled differently between WebUI and API #5222

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

Originally created by @maximumG on GitHub (Aug 24, 2021).

NetBox version

v2.11.7

Python version

3.8

Steps to Reproduce

  1. Create 3 custom fields attached to a VRF (or any Netbox object) with a default value of null
name type default
simple-choicefield selection null
simple-textfield text null
simple-date date null
  1. Create a new VRF named test-vrf-webui using the WebUI and let the custom field "blank"

  2. Create a new VRF named test-vrf-api using the API and the following JSON payload

{
    "name": "test-vrf-api"
}

Expected Behavior

The VRF created in point 2. and point 3. should have their custom fields with expected default value of null

WebUI created VRF

{
    "id": 583,
    "url": "http://localhost:4242/api/ipam/vrfs/583/",
   [...]
    "custom_fields": {
        "simple-choicefield": null,
        "simple-date": null,
        "simple-text": null
    }
}

API created VRF

{
    "id": 584,
    "url": "http://localhost:4242/api/ipam/vrfs/584/",
   [...]
    "custom_fields": {
        "simple-choicefield": null,
        "simple-date": null,
        "simple-text": null
    }
}

Observed Behavior

The VRF created in point 2. with the WebUI is created with custom fields that do not respect the default value set.

{
    "id": 583,
    "url": "http://localhost:4242/api/ipam/vrfs/583/",
   [...]
    "custom_fields": {
        "simple-choicefield": "",
        "simple-date": null,
        "simple-text": ""
    }
}

This behavior has been observed for all custom fields that are not Django form.DateField class. I already described the issue and its root cause in a comment here and is manly due to the way form.Fields subclasses handle empty value.

Originally created by @maximumG on GitHub (Aug 24, 2021). ### NetBox version v2.11.7 ### Python version 3.8 ### Steps to Reproduce 1. Create 3 custom fields attached to a VRF (or any Netbox object) with a default value of `null` | name | type | default | |-------------------- |----------- |--------- | | simple-choicefield | selection | null | | simple-textfield | text | null | | simple-date | date | null | 2. Create a new VRF named `test-vrf-webui` using the WebUI and let the custom field "blank" 3. Create a new VRF named `test-vrf-api` using the API and the following JSON payload ```json { "name": "test-vrf-api" } ``` ### Expected Behavior The VRF created in point 2. and point 3. should have their custom fields with expected default value of `null` **WebUI created VRF** ```json { "id": 583, "url": "http://localhost:4242/api/ipam/vrfs/583/", [...] "custom_fields": { "simple-choicefield": null, "simple-date": null, "simple-text": null } } ``` **API created VRF** ```json { "id": 584, "url": "http://localhost:4242/api/ipam/vrfs/584/", [...] "custom_fields": { "simple-choicefield": null, "simple-date": null, "simple-text": null } } ``` ### Observed Behavior The VRF created in point 2. with the WebUI is created with custom fields that do not respect the default value set. ```json { "id": 583, "url": "http://localhost:4242/api/ipam/vrfs/583/", [...] "custom_fields": { "simple-choicefield": "", "simple-date": null, "simple-text": "" } } ``` This behavior has been observed for all custom fields that are not Django `form.DateField` class. I already described the issue and its root cause in a comment [here](https://github.com/netbox-community/netbox/issues/6725#issuecomment-902549717) and is manly due to the way form.Fields subclasses handle empty value.
adam added the type: bug label 2025-12-29 19:25:37 +01:00
adam closed this issue 2025-12-29 19:25:37 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 24, 2021):

v2.11.7

Have you tried this on v2.11.12 (released yesterday)? This should have been addressed by #5968.

@jeremystretch commented on GitHub (Aug 24, 2021): > v2.11.7 Have you tried this on v2.11.12 (released yesterday)? This should have been addressed by #5968.
Author
Owner

@maximumG commented on GitHub (Aug 25, 2021):

After playing with release 2.11.12 I confirm that the issue has been fixed. Thanks for the job @jeremystretch !

@maximumG commented on GitHub (Aug 25, 2021): After playing with release 2.11.12 I confirm that the issue has been fixed. Thanks for the job @jeremystretch !
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5222