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

ValueError in web UI after REST API accepts invalid custom-field choice-set data #14755

Closed
jeffgdotorg opened this issue Jan 9, 2024 · 2 comments · Fixed by #14804
Closed
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@jeffgdotorg
Copy link
Contributor

jeffgdotorg commented Jan 9, 2024

Deployment Type

Self-hosted

NetBox Version

v3.7.0

Python Version

3.10

Steps to Reproduce

  1. Start with a fresh NetBox 3.7.0 installation and database
  2. Post a custom-field choice-set whose choices are lists with just one element each (should be two elements each):
curl -H "Authorization: Token ${NETBOX_TOKEN}" \
  'http://192.168.64.3/api/extras/custom-field-choice-sets/' \
  -H 'accept: application/json'   -H 'Content-Type: application/json' \
  -d '[ { "name": "test1", "extra_choices": [ ["choice1"], ["choice2"] ] } ]'
  1. Log in to the web UI, navigate to Customization -> Custom Field Choices, and click on the test1 entry

Expected Behavior

The REST API should reject the POST data as invalid

AND/OR

The web UI should render a dialog showing that the choice set's choices have undefined labels

Observed Behavior

The REST API cheerfully creates the choice set with the choice labels undefined.

AND

The web UI displays an unstyled ValueError:

<class 'ValueError'>

Need 2 values to unpack in for loop; got 1. 

Python version: 3.10.12
NetBox version: 3.7.0
Plugins: None installed

This problem was originally reported by @jordanrvillarreal.

@jeffgdotorg jeffgdotorg added type: bug A confirmed report of unexpected behavior in the application status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available labels Jan 9, 2024
Julio-Oliveira-Encora pushed a commit to Julio-Oliveira-Encora/netbox that referenced this issue Jan 16, 2024
…epts invalid custom-field choice-set data
@jeremystretch
Copy link
Member

@Julio-Oliveira-Encora I see that you've submitted a PR for this. If you'd like to own this issue, please comment here so that it can be assigned to you. Thanks!

@Julio-Oliveira-Encora
Copy link
Contributor

@jeremystretch

Please, fell free to assigned it to me.

@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 Jan 16, 2024
jeremystretch added a commit that referenced this issue Jan 19, 2024
#14804)

* Fixes #14755: ValueError in web UI after REST API accepts invalid custom-field choice-set data

* PR Comments Addressed

* Set max_length=2 on extra_choices items; remove custom validation logic

* Move test for invalid choices to CustomFieldChoiceSetTest

* Omit unused imports

---------

Co-authored-by: julio.oliveira <julio.oliveira@alertmedia.com>
Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
jeremystretch added a commit that referenced this issue Jan 19, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
3 participants