Custom Script MultiObjectVar cannot be filled from URL parameter #3599

Closed
opened 2025-12-29 18:30:04 +01:00 by adam · 3 comments
Owner

Originally created by @mrfroggg on GitHub (Apr 22, 2020).

Originally assigned to: @steffann on GitHub.

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.

Originally created by @mrfroggg on GitHub (Apr 22, 2020). Originally assigned to: @steffann on GitHub. <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### 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", ) ``` 2. Try to put a valid device ID in URL parameter ( http://netbox/extra/scripts/myscript/Myclass/?test=1 ) 3. Or list-type format (?test=[1,2]) <!-- What did you expect to happen? --> ### Expected Behavior Field should contain the value of ID in specified in URL parameter test (GET) <!-- What happened instead? --> ### 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.
adam added the type: bugstatus: accepted labels 2025-12-29 18:30:04 +01:00
adam closed this issue 2025-12-29 18:30:05 +01:00
Author
Owner

@steffann commented on GitHub (Apr 27, 2020):

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?

@steffann commented on GitHub (Apr 27, 2020): 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?
Author
Owner

@sdktr commented on GitHub (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: https://github.com/netbox-community/netbox/issues/4313

@sdktr commented on GitHub (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: https://github.com/netbox-community/netbox/issues/4313
Author
Owner

@steffann commented on GitHub (May 13, 2020):

edit: #4313

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

@steffann commented on GitHub (May 13, 2020): > edit: #4313 That makes the choice very clear :) Working on it!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3599