Incorrect Field Type in Response for GET /api/dcim/device-type(/{id}/) Model Schema #9264

Closed
opened 2025-12-29 20:47:38 +01:00 by adam · 4 comments
Owner

Originally created by @jniec-js on GitHub (Feb 17, 2024).

Originally assigned to: @abhi1693 on GitHub.

Deployment Type

Self-hosted

NetBox Version

v3.7.1

Python Version

3.11

Steps to Reproduce

  1. Look at the API documentation for /api/dcim/device-types/{id}, on the demo site (https://demo.netbox.dev/api/schema/swagger-ui/#/dcim/dcim_device_types_retrieve) and inspect the Schema for DeviceType, see that front_image and rear_image are declared as strings
  2. Use https://demo.netbox.dev/dcim/device-types/7/ as an example to test, a device_type that has no front or rear images associated with the object
  3. Send an http GET request to /api/dcim/device-types/7/ using the netbox demo's swagger documentation website here: https://demo.netbox.dev/api/schema/swagger-ui/#/dcim/dcim_device_types_retrieve, click "try it out!", for the ID, enter in 7, click Execute
  4. Observe that the response payload for front_image and/or rear_image is set to null and not an empty string despite the Model specifying "string" for the type and not specfying "nullable:true" on the field. See screenshots below:

Expected Behavior

I expected that the types in the response from the query would match what types are defined in the model.

Observed Behavior

We get back the wrong type in the response from the API when a front and/or rear image is not attached to a device_type.
Screenshot from 2024-02-16 21-12-05
Screenshot from 2024-02-16 21-11-55

Originally created by @jniec-js on GitHub (Feb 17, 2024). Originally assigned to: @abhi1693 on GitHub. ### Deployment Type Self-hosted ### NetBox Version v3.7.1 ### Python Version 3.11 ### Steps to Reproduce 1. Look at the API documentation for /api/dcim/device-types/{id}, on the demo site (https://demo.netbox.dev/api/schema/swagger-ui/#/dcim/dcim_device_types_retrieve) and inspect the Schema for DeviceType, see that front_image and rear_image are declared as strings 2. Use https://demo.netbox.dev/dcim/device-types/7/ as an example to test, a device_type that has no front or rear images associated with the object 3. Send an http GET request to /api/dcim/device-types/7/ using the netbox demo's swagger documentation website here: https://demo.netbox.dev/api/schema/swagger-ui/#/dcim/dcim_device_types_retrieve, click "try it out!", for the ID, enter in 7, click Execute 4. Observe that the response payload for front_image and/or rear_image is set to null and not an empty string despite the Model specifying "string" for the type and not specfying "nullable:true" on the field. See screenshots below: ### Expected Behavior I expected that the types in the response from the query would match what types are defined in the model. ### Observed Behavior We get back the wrong type in the response from the API when a front and/or rear image is not attached to a device_type. ![Screenshot from 2024-02-16 21-12-05](https://github.com/netbox-community/netbox/assets/141941931/05307258-aab8-4b30-9ce8-dca0c646668c) ![Screenshot from 2024-02-16 21-11-55](https://github.com/netbox-community/netbox/assets/141941931/e460af63-4409-4b46-8af8-221d974d88dc)
adam added the type: bugstatus: acceptedseverity: lowtopic: OpenAPI labels 2025-12-29 20:47:38 +01:00
adam closed this issue 2025-12-29 20:47:38 +01:00
Author
Owner

@jeremystretch commented on GitHub (Feb 20, 2024):

I expected that the types in the response from the query would match what types are defined in the model.

Please specify exactly what you expect to see in the specification for the field.

@jeremystretch commented on GitHub (Feb 20, 2024): > I expected that the types in the response from the query would match what types are defined in the model. Please specify exactly what you expect to see in the specification for the field.
Author
Owner

@jniec-js commented on GitHub (Feb 20, 2024):

I would expect that the specification either say "nullable: true" or the response be an empty string for both fields.

@jniec-js commented on GitHub (Feb 20, 2024): I would expect that the specification either say "nullable: true" _or_ the response be an empty string for both fields.
Author
Owner

@jeremystretch commented on GitHub (Feb 20, 2024):

Can you point to an example of this elsewhere in the spec?

@jeremystretch commented on GitHub (Feb 20, 2024): Can you point to an example of this elsewhere in the spec?
Author
Owner

@jniec-js commented on GitHub (Feb 20, 2024):

I see other fields in the same model as marked 'nullable: true'. Though these are objects, I am unsure if that matters for this or not though.

Screenshot from 2024-02-20 10-49-59

@jniec-js commented on GitHub (Feb 20, 2024): I see other fields in the same model as marked 'nullable: true'. Though these are objects, I am unsure if that matters for this or not though. ![Screenshot from 2024-02-20 10-49-59](https://github.com/netbox-community/netbox/assets/141941931/164a3d5c-2bb3-4eac-9358-e9d960131972)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9264