Skip to content

Default values for custom_fields are ignored in API when custom_fields section is used #18669

Closed
@antonvdl

Description

@antonvdl

Deployment Type

Self-hosted

NetBox Version

v4.2.3

Python Version

3.12

Steps to Reproduce

  1. Create multiple custom_fields with object type IPAM > Prefix
  • primary_subnet, type: boolean, required: yes, default value: true
  • ripe_admin, type: text, required: no, default value: "xxx-RIPE"
  • ripe_tech, type: text, required:no
  • ripe_netname, type: text, required: no
  1. Create a new prefix using API without custom_fields
    { "prefix": "10.0.0.0/24", "status": "active", "description": "Test prefix", "vlan": "147", "is_pool": false, "tenant": 6 }
  2. Create a new prefix using API with only "primary_subnet" as custom_field
    { "prefix": "10.0.0.0/24", "status": "active", "description": "Test prefix", "vlan": "147", "is_pool": false, "tenant": 6, "custom_fields": { "primary_subnet": true } }
  3. Create a new prefix using API with only "ripe_netname" as custom_field
    { "prefix": "10.0.0.0/24", "status": "active", "description": "Test prefix", "vlan": "147", "is_pool": false, "tenant": 6, "custom_fields": { "ripe_netname": "test" } }

Expected Behavior

  1. Custom fields are created
  2. Prefix is created with default values for custom_fields primary_subnet and ripe_admin. Other custom_fields are null
  3. Prefix is created with supplied value for custom_field primary_subnet, default value for ripe_admin. Other custom_fields are null
  4. Prefix is created with default values for custom_fields primary_subnet and ripe_admin. ripe_netname gets the supplied value and ripe_tech remains null

Observed Behavior

As soon as a custom_fields section is available in the POST Body then the default values for all custom_fields are ignored.
When I do not send the custom_fields section at all then the default values are used correctly.

  1. Custom fields are created (OK)
  2. Prefix is created with default values for primary_subnet and ripe_admin (OK)
  3. Prefix is created with primary_subnet set to true but other custom_fields are empty -> default value for ripe_admin is ignored
  4. Prefix is not created because primary_subnet (required) is not supplied -> default value for primary_subnet is ignored

Metadata

Metadata

Assignees

Labels

severity: lowDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions