Divergent data structures in application / API schema #9750

Closed
opened 2025-12-29 21:22:02 +01:00 by adam · 1 comment
Owner

Originally created by @ByteOtter on GitHub (May 27, 2024).

Deployment Type

Self-hosted

NetBox Version

v3.6.9, v4.0.3

Python Version

3.11

Steps to Reproduce

  1. Generate API client using the current API schema using the schema's data model to determine if fields are optional or not.
  2. Have serde or similar packages handle translation of JSON responses into data structures
  3. Have it fail as fields from GET responses of the Interface-endpoint can be null despite the schema stating nullable = False

Error Message:

error decoding response body: invalid type: null, expected a string at line 1 column 920

Expected Behavior

Application code and API schema should be in agreement whether fields in Interface or Device should be nullable or not.

Observed Behavior

API client fails to translate JSON objects into rust struct as the client, based off of the NetBox API schema, expects fields like 2vpn_termination to not be null. This field is optional when creating a Interface, but apparently cannot be null according to the schema.
The application code confirms it to be nullable:

l2vpn_termination = NestedL2VPNTerminationSerializer(read_only=True, allow_null=True)

This error appears whether tested against our internal v3.6.9 version of NetBox as well as the offical demo instance with both schemata being used to generate a client each. With the same result.

Originally created by @ByteOtter on GitHub (May 27, 2024). ### Deployment Type Self-hosted ### NetBox Version v3.6.9, v4.0.3 ### Python Version 3.11 ### Steps to Reproduce 1. Generate API client using the current API schema using the schema's data model to determine if fields are optional or not. 2. Have `serde` or similar packages handle translation of JSON responses into data structures 3. Have it fail as fields from `GET` responses of the `Interface`-endpoint can be `null` despite the schema stating `nullable = False` Error Message: ``` error decoding response body: invalid type: null, expected a string at line 1 column 920 ``` ### Expected Behavior Application code and API schema should be in agreement whether fields in `Interface` or `Device` should be `nullable` or not. ### Observed Behavior API client fails to translate JSON objects into rust struct as the client, based off of the NetBox API schema, expects fields like `2vpn_termination` to not be `null`. This field is optional when creating a Interface, but apparently cannot be null according to the schema. The application code confirms it to be nullable: ```python l2vpn_termination = NestedL2VPNTerminationSerializer(read_only=True, allow_null=True) ``` This error appears whether tested against our internal `v3.6.9` version of NetBox as well as the offical [demo instance](https://demo.netbox.dev/) with both schemata being used to generate a client each. With the same result.
adam closed this issue 2025-12-29 21:22:02 +01:00
Author
Owner

@DanSheps commented on GitHub (May 27, 2024):

According to the schema @ https://demo.netbox.dev/api/schema/

For both Interface and VMInterface, l2vpn_termination is nullable. This seems to be an issue with your API client.

@DanSheps commented on GitHub (May 27, 2024): According to the schema @ https://demo.netbox.dev/api/schema/ For both `Interface` and `VMInterface`, `l2vpn_termination` is nullable. This seems to be an issue with your API client.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9750