Allow MultiObjectVar to accept PKs higher than 9 when script is called with a single URL param #6516

Closed
opened 2025-12-29 19:41:51 +01:00 by adam · 0 comments
Owner

Originally created by @jsenecal on GitHub (May 26, 2022).

Originally assigned to: @kkthxbye-code on GitHub.

NetBox version

v3.2.3

Python version

3.9

Steps to Reproduce

  1. Start with a clean, empty installation
  2. Create a custom script testscript.py:
from extras.scripts import *
from dcim.models import Device

class MultiObjectVarTest(Script):
    devices = MultiObjectVar (model=Device)

    def run(data, commit):
        pass
  1. Create a dummy Manufacturer and DeviceType
  2. Fill the database with multiple Device objects (more than 10)
  3. Confirm that devices have at least picked up PKs 1 thru 10
  4. Access http://netbox/extras/scripts/testscript.MultiObjectVarTest/?devices=1 (1 is a valid, existing device pk) -> Confirm that the devices field is properly populated with the Device which has pk 1
  5. Access http://netbox/extras/scripts/testscript.MultiObjectVarTest/?devices=10 (10 is also a valid, existing device pk) -> Notice that the devices field is now empty

Expected Behavior

Access http://netbox/extras/scripts/testscript.MultiObjectVarTest/?devices=10 (10 is a valid, existing device pk) and confirm that the devices field is properly populated with the Device which has pk 10

Observed Behavior

The devices field is not populated with the Device which has PK 10, but can be searched manually.

I believe that this is due to the widget only prefetching the first few items and not knowing what to do with higher-count objects.

Originally created by @jsenecal on GitHub (May 26, 2022). Originally assigned to: @kkthxbye-code on GitHub. ### NetBox version v3.2.3 ### Python version 3.9 ### Steps to Reproduce 0. Start with a clean, empty installation 1. Create a custom script `testscript.py`: > ```python > from extras.scripts import * > from dcim.models import Device > > class MultiObjectVarTest(Script): > devices = MultiObjectVar (model=Device) > > def run(data, commit): > pass > ``` 2. Create a dummy `Manufacturer` and `DeviceType` 3. Fill the database with multiple `Device` objects (more than 10) 4. Confirm that devices have at least picked up PKs 1 thru 10 5. Access `http://netbox/extras/scripts/testscript.MultiObjectVarTest/?devices=1` (1 is a valid, existing device pk) -> Confirm that the `devices` field is properly populated with the `Device` which has pk 1 6. Access `http://netbox/extras/scripts/testscript.MultiObjectVarTest/?devices=10` (10 is also a valid, existing device pk) -> Notice that the `devices` field is now empty ### Expected Behavior Access `http://netbox/extras/scripts/testscript.MultiObjectVarTest/?devices=10` (10 is a valid, existing device pk) and confirm that the `devices` field is properly populated with the `Device` which has pk 10 ### Observed Behavior The devices field is not populated with the `Device` which has PK 10, but can be searched manually. I believe that this is due to the widget only prefetching the first few items and not knowing what to do with higher-count objects.
adam added the type: bugstatus: accepted labels 2025-12-29 19:41:51 +01:00
adam closed this issue 2025-12-29 19:41:51 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6516