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

Custom Script MultiObjectVar cannot be filled from URL parameter #4525

Closed
mrfroggg opened this issue Apr 22, 2020 · 3 comments · Fixed by #4692
Closed

Custom Script MultiObjectVar cannot be filled from URL parameter #4525

mrfroggg opened this issue Apr 22, 2020 · 3 comments · Fixed by #4692
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@mrfroggg
Copy link

Environment

  • Python version: 3.7
  • NetBox version: 2.7.12

I'm building a custom script with multiple fields that I want to pre-fill from a a URL (that I will generate from a Custom Link).
It works, except for MultiObjectVar (Multiple Select) variable type.

Steps to Reproduce

  1. Create Custom Script with a MultiObjectVar field (named "test")
test = MultiObjectVar(
    queryset=Device.objects.filter(status="active"),
    required=True,
    label="Test field", 
)
  1. Try to put a valid device ID in URL parameter ( http://netbox/extra/scripts/myscript/Myclass/?test=1 )
  2. Or list-type format (?test=[1,2])

Expected Behavior

Field should contain the value of ID in specified in URL parameter test (GET)

Observed Behavior

with step 1 and 2: It doesn't fill any field. MultiObjectVar is blank/null. No error.

With step 3, as a MultiObjectVar should contain a list object, it gives:
class 'ValueError'
invalid literal for int() with base 10: ']'

If I add "default=[1,2]" to step 1 MultiObjectVar, it will fill it with the right values.
"default", for this MultiObjectVar variable, needs a list object. int() will give an error.

If you replace MultiObjectVar with ObjectVar and repeat step 2, it will fill the field with the right value.

Filling fields from GET parameters seems to work for all other field type I tried.

We should be able to pass multiple values using GET requests for such field type.

@steffann
Copy link
Contributor

Is ?test=[1,2] the syntax we want for this? I personally would prefer to make the brackets optional and also allow ?test=1,2 and ?test=1. Any objections to that?

@sdktr
Copy link
Contributor

sdktr commented Apr 27, 2020

Let’s try to keep it consistent between other API filters? I think the rest api requires test=1&test=2 to dictate an ‘or’ filter?

edit: #4313

@steffann
Copy link
Contributor

edit: #4313

That makes the choice very clear :) Working on it!

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application labels May 26, 2020
jeremystretch added a commit that referenced this issue May 26, 2020
…-data

Fixes #4525: Allow passing initial data to custom script MultiObjectVar
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
4 participants