Unable to add images to a Device Type using a PATCH request #9325

Closed
opened 2025-12-29 20:48:31 +01:00 by adam · 12 comments
Owner

Originally created by @sjurtf on GitHub (Mar 6, 2024).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

v3.7.3

Python Version

3.8

Steps to Reproduce

  1. Clone or download https://github.com/netbox-community/Device-Type-Library-Import/
  2. Run the importer NETBOX_URL=<your netbox instance> REPO_URL=https://github.com/netbox-community/devicetype-library/ NETBOX_TOKEN=<your netbox token> python3 nb-dt-import.py

This used to work, I believe this issue related to the change in this commit: 839609d101.

It works in v3.7.2.

Expected Behavior

Images should be successfully uploaded and added to the Device Type.

Observed Behavior

Device-Type-Library-Import will get HTTP 400 error from the API when trying to upload images.

Example log message
Images {'front_image': '/Users/username/tmp/Device-Type-Library-Import/repo/elevation-images/Dell/dell-powervault-nx3240.front.png', 'rear_image': '/Users/username/tmp/Device-Type-Library-Import/repo/elevation-images/Dell/dell-powervault-nx3240.rear.png'} updated at https://localhost/api/dcim/device-types/393/: <Response [400]>

Further inspection of the response body shows:
{"front_image":["Enter a valid URL."],"rear_image":["Enter a valid URL."]}

Originally created by @sjurtf on GitHub (Mar 6, 2024). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version v3.7.3 ### Python Version 3.8 ### Steps to Reproduce 1. Clone or download https://github.com/netbox-community/Device-Type-Library-Import/ 2. Run the importer `NETBOX_URL=<your netbox instance> REPO_URL=https://github.com/netbox-community/devicetype-library/ NETBOX_TOKEN=<your netbox token> python3 nb-dt-import.py` This used to work, I believe this issue related to the change in this commit: https://github.com/netbox-community/netbox/commit/839609d101aeb44d94f464813e87c6eb1374afd0. It works in v3.7.2. ### Expected Behavior Images should be successfully uploaded and added to the Device Type. ### Observed Behavior Device-Type-Library-Import will get HTTP 400 error from the API when trying to upload images. Example log message ```Images {'front_image': '/Users/username/tmp/Device-Type-Library-Import/repo/elevation-images/Dell/dell-powervault-nx3240.front.png', 'rear_image': '/Users/username/tmp/Device-Type-Library-Import/repo/elevation-images/Dell/dell-powervault-nx3240.rear.png'} updated at https://localhost/api/dcim/device-types/393/: <Response [400]>``` Further inspection of the response body shows: ```{"front_image":["Enter a valid URL."],"rear_image":["Enter a valid URL."]}```
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 20:48:31 +01:00
adam closed this issue 2025-12-29 20:48:32 +01:00
Author
Owner

@jbemmel commented on GitHub (Mar 6, 2024):

+1 just hitting this very same issue today

@jbemmel commented on GitHub (Mar 6, 2024): +1 just hitting this very same issue today
Author
Owner

@joshuajcoronado commented on GitHub (Mar 8, 2024):

+1, same same

@joshuajcoronado commented on GitHub (Mar 8, 2024): +1, same same
Author
Owner

@jeremystretch commented on GitHub (Mar 8, 2024):

Bug reports which reference code outside NetBox core are not actionable. If you believe there is a bug in the REST API, please provide suitable reproduction steps that do not rely on third party code, which someone else can follow to reproduce the suspect behavior. (This may be as simple as posting an example API request.)

@jeremystretch commented on GitHub (Mar 8, 2024): Bug reports which reference code outside NetBox core are not actionable. If you believe there is a bug in the REST API, please provide suitable reproduction steps **that do not rely on third party code**, which someone else can follow to reproduce the suspect behavior. (This may be as simple as posting an example API request.)
Author
Owner

@jbemmel commented on GitHub (Mar 8, 2024):

See https://github.com/netbox-community/netbox/compare/develop...jbemmel:netbox:develop#diff-5497394955b13b98e5274b262322f5a175a9b2c1016ffd173f556696933ef2eaR329

The issue is in netbox/dcim/api/serializers.py, as referenced in the commit mentioned in the bug report. Removing these 2 lines fixes the issue

image

@jbemmel commented on GitHub (Mar 8, 2024): See https://github.com/netbox-community/netbox/compare/develop...jbemmel:netbox:develop#diff-5497394955b13b98e5274b262322f5a175a9b2c1016ffd173f556696933ef2eaR329 The issue is in netbox/dcim/api/serializers.py, as referenced in the commit mentioned in the bug report. Removing these 2 lines fixes the issue ![image](https://github.com/netbox-community/netbox/assets/2031627/189fb4c1-58b3-471d-a635-b222c9c47abd)
Author
Owner

@jeremystretch commented on GitHub (Mar 8, 2024):

Again, no action will be taken without sufficient reproduction details.

@jeremystretch commented on GitHub (Mar 8, 2024): Again, no action will be taken without sufficient reproduction details.
Author
Owner

@jbemmel commented on GitHub (Mar 8, 2024):

docker run -e "NETBOX_URL=http://172.17.0.1:8000/" -e "NETBOX_TOKEN=0123456789abcdef0123456789abcdef01234567" -e "VENDORS=Nokia" ghcr.io/minitriga/netbox-device-type-library-import

adjust the IP address and Netbox token to your setup

Yes, that depends on third party code, but it's a single line command that anyone can easily execute. Kindly stop citing unreasonable policies

@jbemmel commented on GitHub (Mar 8, 2024): ``` docker run -e "NETBOX_URL=http://172.17.0.1:8000/" -e "NETBOX_TOKEN=0123456789abcdef0123456789abcdef01234567" -e "VENDORS=Nokia" ghcr.io/minitriga/netbox-device-type-library-import ``` adjust the IP address and Netbox token to your setup Yes, that depends on third party code, but it's a single line command that anyone can easily execute. Kindly stop citing unreasonable policies
Author
Owner

@jeremystretch commented on GitHub (Mar 8, 2024):

Per the bug report template:

Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox.

If you're unwilling to provide the information needed, I'll proceed with closing out this issue.

@jeremystretch commented on GitHub (Mar 8, 2024): Per the bug report template: > Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. **If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made**: Don't rely on a client library such as pynetbox. If you're unwilling to provide the information needed, I'll proceed with closing out this issue.
Author
Owner

@jbemmel commented on GitHub (Mar 8, 2024):

If you're unwilling to provide the information needed, I'll proceed with closing out this issue.

I am trying to be helpful here, but these kinds of comments are discouraging. I did not open this bug report, I am merely affected by the same issue and I know where the problem is and how to fix it.

I am not "unwilling", but I do get irritated by all this and I wish you all the best with resolving your issues

@jbemmel commented on GitHub (Mar 8, 2024): > > If you're unwilling to provide the information needed, I'll proceed with closing out this issue. I am trying to be helpful here, but these kinds of comments are discouraging. I did not open this bug report, I am merely affected by the same issue and I know where the problem is and how to fix it. I am not "unwilling", but I do get irritated by all this and I wish you all the best with resolving your issues
Author
Owner

@jeremystretch commented on GitHub (Mar 8, 2024):

I am trying to be helpful here

You're claiming that there's a bug with a certain API request, yet you won't share the actual request you're making. You expect someone else to figure that out for you. This is unreasonable, and it is why our reporting policies clearly define the information we require to investigate a bug report. If you're unwilling to abide by these policies, please refrain from engaging with the project as it's not a productive use of time.

@jeremystretch commented on GitHub (Mar 8, 2024): > I am trying to be helpful here You're claiming that there's a bug with a certain API request, yet you won't share the actual request you're making. You expect someone else to figure that out for you. This is unreasonable, and it is why our reporting policies clearly define the information we require to investigate a bug report. If you're unwilling to abide by these policies, please refrain from engaging with the project as it's not a productive use of time.
Author
Owner

@kkthxbye-code commented on GitHub (Mar 8, 2024):

  • Create a device type (id 8 in this case)
  • Get an image, test.png in this case
  • Run the following command to upload image: curl -X PATCH -F 'front_image=@test.png' http://127.0.0.1:8000/api/dcim/device-types/8/ -H "Authorization: Token TOKENHERE"

Returns: {"front_image":["Enter a valid URL."]}

Reverting 839609d101 makes the above curl command succede. The rest API also returns the wrong string in front_image/rear_image when the commit is not reverted:

Without the bad commit:
"front_image": "http://127.0.0.1:8000/media/devicetype-images/test.png",

With the bad commit:
"front_image": "devicetype-images/test.png",

Lastly it's immediately obvious from looking at the commit that it's wrong. The two model fields are ImageFields, obviously not URLFields. Not sure how this was not caught by the submitter nor the reviewer, and it seems like the unit tests doesn't catch this either.

@kkthxbye-code commented on GitHub (Mar 8, 2024): * Create a device type (id 8 in this case) * Get an image, test.png in this case * Run the following command to upload image: `curl -X PATCH -F 'front_image=@test.png' http://127.0.0.1:8000/api/dcim/device-types/8/ -H "Authorization: Token TOKENHERE"` Returns: `{"front_image":["Enter a valid URL."]}` Reverting https://github.com/netbox-community/netbox/commit/839609d101aeb44d94f464813e87c6eb1374afd0 makes the above curl command succede. The rest API also returns the wrong string in front_image/rear_image when the commit is not reverted: Without the bad commit: `"front_image": "http://127.0.0.1:8000/media/devicetype-images/test.png",` With the bad commit: `"front_image": "devicetype-images/test.png",` Lastly it's immediately obvious from looking at the commit that it's wrong. The two model fields are ImageFields, obviously not URLFields. Not sure how this was not caught by the submitter nor the reviewer, and it seems like the unit tests doesn't catch this either.
Author
Owner

@jeremystretch commented on GitHub (Mar 8, 2024):

@kkthxbye-code thanks for documenting those very simple reproduction steps. Given that you've already looked into the underlying issue, would you like to submit a PR for this?

@jeremystretch commented on GitHub (Mar 8, 2024): @kkthxbye-code thanks for documenting those very simple reproduction steps. Given that you've already looked into the underlying issue, would you like to submit a PR for this?
Author
Owner

@jeremystretch commented on GitHub (Mar 13, 2024):

Guess I'll take this one.

@jeremystretch commented on GitHub (Mar 13, 2024): Guess I'll take this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9325