MultiObjectVar does not accept initial data via URL #4208

Closed
opened 2025-12-29 18:33:52 +01:00 by adam · 4 comments
Owner

Originally created by @rodvand on GitHub (Oct 22, 2020).

Environment

  • Python version: 3.7.5
  • NetBox version: 2.9.7

Steps to Reproduce

  1. Create a custom script utilising MultiObjectVar. Example ob_var.py:
from extras.scripts import *
from virtualization.models import VirtualMachine

class ObjectVarTest(Script):
    vm = MultiObjectVar(
            model=VirtualMachine
            )

    def run(data, commit):
        pass
  1. Find the ID of one of your Virtual Machines
  2. Try using the URL https://your.netbox.install/extras/scripts/ob_var.ObjectVarTest/?vm=13

Expected Behavior

That the initial field for a Virtual Machine would be pre-filled with my VM number 13.

Observed Behaviour

Nothing is pre-filled.

Change the MultiObjectVar to ObjectVar and repeat the test - the field is pre-filled with the Virtual Machine.

Originally created by @rodvand on GitHub (Oct 22, 2020). <!-- 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/g/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.5 * NetBox version: 2.9.7 ### Steps to Reproduce 1. Create a custom script utilising MultiObjectVar. Example ob_var.py: ``` from extras.scripts import * from virtualization.models import VirtualMachine class ObjectVarTest(Script): vm = MultiObjectVar( model=VirtualMachine ) def run(data, commit): pass ``` 2. Find the ID of one of your Virtual Machines 3. Try using the URL https://your.netbox.install/extras/scripts/ob_var.ObjectVarTest/?vm=13 <!-- What did you expect to happen? --> ### Expected Behavior That the initial field for a Virtual Machine would be pre-filled with my VM number 13. <!-- What happened instead? --> ### Observed Behaviour Nothing is pre-filled. Change the MultiObjectVar to ObjectVar and repeat the test - the field is pre-filled with the Virtual Machine.
adam added the type: bugstatus: needs ownerpending closure labels 2025-12-29 18:33:52 +01:00
adam closed this issue 2025-12-29 18:33:52 +01:00
Author
Owner

@jeremystretch commented on GitHub (Oct 27, 2020):

It seems that the field does accept initial data, but treats the value as a list, so muilt-character values don't work correctly. E.g. ?vm=9 works but ?vm=10 does not because it's interpreted as passing [1, 0].

@jeremystretch commented on GitHub (Oct 27, 2020): It seems that the field _does_ accept initial data, but treats the value as a list, so muilt-character values don't work correctly. E.g. `?vm=9` works but `?vm=10` does not because it's interpreted as passing `[1, 0]`.
Author
Owner

@jeremystretch commented on GitHub (Oct 27, 2020):

I've dug into this a bit but can't account for the bug: AFAICT the form field is being initialized with the correct data. It may be related to the Select2 library. This isn't limited to custom scripts, either: Config context object selection is another example where multi-character initial values don't work.

@jeremystretch commented on GitHub (Oct 27, 2020): I've dug into this a bit but can't account for the bug: AFAICT the form field is being initialized with the correct data. It may be related to the Select2 library. This isn't limited to custom scripts, either: Config context object selection is another example where multi-character initial values don't work.
Author
Owner

@stale[bot] commented on GitHub (Jan 1, 2021):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@stale[bot] commented on GitHub (Jan 1, 2021): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@stale[bot] commented on GitHub (Jan 17, 2021):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@stale[bot] commented on GitHub (Jan 17, 2021): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4208