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

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

Closed
sjurtf opened this issue Mar 6, 2024 · 12 comments · Fixed by #15417
Closed

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

sjurtf opened this issue Mar 6, 2024 · 12 comments · Fixed by #15417
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

@sjurtf
Copy link

sjurtf commented Mar 6, 2024

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: 839609d.

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."]}

@sjurtf sjurtf added the type: bug A confirmed report of unexpected behavior in the application label Mar 6, 2024
@jbemmel
Copy link

jbemmel commented Mar 6, 2024

+1 just hitting this very same issue today

@joshuajcoronado
Copy link

+1, same same

@jeremystretch
Copy link
Member

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 jeremystretch added the status: revisions needed This issue requires additional information to be actionable label Mar 8, 2024
@jbemmel

This comment was marked as off-topic.

@jeremystretch

This comment was marked as off-topic.

@jbemmel

This comment was marked as off-topic.

@jeremystretch

This comment was marked as off-topic.

@jbemmel

This comment was marked as off-topic.

@jeremystretch

This comment was marked as off-topic.

@kkthxbye-code
Copy link
Contributor

  • 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 '[email protected]' http://127.0.0.1:8000/api/dcim/device-types/8/ -H "Authorization: Token TOKENHERE"

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

Reverting 839609d 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.

@jeremystretch jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: medium Results in substantial degraded or broken functionality for specfic workflows and removed status: revisions needed This issue requires additional information to be actionable labels Mar 8, 2024
@jeremystretch
Copy link
Member

@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
Copy link
Member

Guess I'll take this one.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Mar 13, 2024
@jeremystretch jeremystretch self-assigned this Mar 13, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 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
5 participants