Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When attempting to create a new IP and set custom fields using a POST request to the API, the custom fields are being created as null, even when values are provided in the request body #13746

Closed
matheuskshn opened this issue Sep 12, 2023 · 3 comments · Fixed by #13889
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@matheuskshn
Copy link

matheuskshn commented Sep 12, 2023

NetBox version

v3.6.1

Python version

3.9

Steps to Reproduce

Before encountering this issue, we upgraded our NetBox installation from version 2.6.4 to 3.6.1, following the guidelines provided in the official documentation.

  1. Initiate a POST request to create a new IP address, including custom field values, through the API endpoint (the exact endpoint has been obfuscated for security reasons). The command to initiate this request looks something like:
curl -k -X POST https://netbox.example.com/api/ipam/prefixes/87946/available-ips/ \
-H "Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
  "description": "Test Description",
    "custom_fields": {
      "A_strServiceRequest": " Test request",
      "B_strRequester": "Test",
      "C_strEmail": "[email protected]",
      "D_strPhoneNumber": "55555555"
   }
}'

POST Response:

{
  "id": 410889,
  "url": "https://netbox.example.com/api/ipam/ip-addresses/410889/",
  "display": "192.168.57.4/22",
  "family": {
    "value": 4,
    "label": "IPv4"
  },
  "address": "192.168.57.4/22",
  "vrf": null,
  "tenant": null,
  "status": {
    "value": "active",
    "label": "Active"
  },
  "role": null,
  "assigned_object_type": null,
  "assigned_object_id": null,
  "assigned_object": null,
  "nat_inside": null,
  "nat_outside": [],
  "dns_name": "",
  "description": "",
  "comments": "",
  "tags": [],
  "custom_fields": {
    "A_strServiceRequest": null,
    "B_strRequester": null,
    "C_strEmail": null,
    "D_strPhoneNumber": null,
    "E_strAdditionalInfo": null
  },
  "created": "2023-09-12T16:35:07.845659Z",
  "last_updated": "2023-09-12T16:35:07.845684Z"
}
  1. Note that the custom fields are returned as null in the response, indicating that they were not set correctly during the POST request.

  2. Now initiate a PATCH request to modify the allocated IP with new custom field values using a command similar to:

curl -k -X PATCH https://netbox.example.com/api/ipam/ip-addresses/410889/ \
-H "Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
  "custom_fields": {
    "A_strServiceRequest": "NewValue1",
    "B_strRequester": "NewValue2",
    "C_strEmail": "NewValue3",
    "D_strPhoneNumber": "NewValue4",
    "E_strAdditionalInfo": "NewValue5"
  }
}'

PATCH Response:

{
  "id": 410889,
  "url": "https://netbox.example.com/api/ipam/ip-addresses/410889/",
  "display": "192.168.57.4/22",
  "family": {
    "value": 4,
    "label": "IPv4"
  },
  "address": "192.168.57.4/22",
  "vrf": null,
  "tenant": null,
  "status": {
    "value": "active",
    "label": "Active"
  },
  "role": null,
  "assigned_object_type": null,
  "assigned_object_id": null,
  "assigned_object": null,
  "nat_inside": null,
  "nat_outside": [],
  "dns_name": "",
  "description": "",
  "comments": "",
  "tags": [],
  "custom_fields": {
    "A_strServiceRequest": "NewValue1",
    "B_strRequester": "NewValue2",
    "C_strEmail": "NewValue3",
    "D_strPhoneNumber": "NewValue4",
    "E_strAdditionalInfo": "NewValue5"
  },
  "created": "2023-09-12T16:35:07.845659Z",
  "last_updated": "2023-09-12T16:36:26.526444Z"
}
  1. Observe that the PATCH request successfully updates the custom field values, as reflected in the response.

Expected Behavior

The custom fields should have accepted and stored the values provided in the initial POST request, instead of being created as null.

Observed Behavior

The custom fields are created as null during the POST request, even though values were provided in the request body. However, the subsequent PATCH request can successfully modify these fields with new values.

@matheuskshn matheuskshn added the type: bug A confirmed report of unexpected behavior in the application label Sep 12, 2023
@lg-dgo
Copy link

lg-dgo commented Sep 13, 2023

I can confirm the described behavior in Netbox version 3.6.1. But not only the custom field values will be ignored, also standard fields, like tenant or dns_name will not be set.

In Netbox version 3.5.9 this error did not exist yet. Here it works as it should.

@netbox-community netbox-community deleted a comment from gitjoob Sep 14, 2023
@JaedanC
Copy link

JaedanC commented Sep 15, 2023

I have noticed similar behaviour to OP regarding Selection fields.

I've tried setting custom Selection fields using POST and PATCH, (tried with value and label), and neither will update the field in 3.6.2-dev. It did work in 3.5.9.

@sc68cal
Copy link
Contributor

sc68cal commented Oct 3, 2023

We seem to be hitting this in the Ansible netbox collection's CI

https://github.com/netbox-community/ansible_modules/actions/runs/6291719867/job/17080388389

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants