Netbox: Custom Script MultiObjectVar cannot be filled from URL parameter

Created on 22 Apr 2020  Â·  3Comments  Â·  Source: netbox-community/netbox

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.

accepted bug

Most helpful comment

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: https://github.com/netbox-community/netbox/issues/4313

All 3 comments

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?

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: https://github.com/netbox-community/netbox/issues/4313

edit: #4313

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robbagithub picture robbagithub  Â·  3Comments

aarjbdea picture aarjbdea  Â·  3Comments

Ali-Yazdani picture Ali-Yazdani  Â·  3Comments

candlerb picture candlerb  Â·  3Comments

soer7022 picture soer7022  Â·  3Comments