Custom Script MultiObjectVar not compatible with APISelectMultiple with selector enabled #8312

Closed
opened 2025-12-29 20:35:13 +01:00 by adam · 2 comments
Owner

Originally created by @FloSch-Nokia on GitHub (Jul 10, 2023).

NetBox version

v3.5.5

Python version

3.10

Steps to Reproduce

Create a custom script like this:

import string
import json

from django.contrib.contenttypes.models import ContentType
from dcim.choices import DeviceFaceChoices, DeviceStatusChoices, CableTypeChoices, InterfaceTypeChoices
from dcim.models import Cable, Device, DeviceRole, DeviceType, FrontPort, Interface, Manufacturer, Site, Platform, PowerPort, PowerOutlet, Rack
from ipam.models import VLAN
from extras.scripts import *
from django.conf import settings
from tenancy.models import Tenant
from django import forms
from utilities.forms.fields import *
from utilities.forms.widgets import APISelect, APISelectMultiple, HTMXSelect


class NewMacVrf(Script):
    class Meta:
        name = "New mac-vrf"
        description = "Add a mac-vrf"
        #field_order = ['macvrf_id', 'description', 'interfaces', 'vlan']

### others objects removed

    interfaces_multi= MultiObjectVar(
        description="Interfaces",
        model=Interface, 
        widget=APISelectMultiple(
            api_url='/api/dcim/interfaces/',
            attrs={'selector' : 'dcim.interface'},
        )
    )  


    def run(self, data, commit):
        output = []
        for key, value in data.items():
            output.append(f"{key}: {value}")
        return '\n'.join(output)

image

The selector works, but if something is selected from the selector its not get append the to the MultiObjectVar, if I use APISelect instead, the interface gets appended, but obviously its than a single object.

Expected Behavior

Actually I would expect that MultiObjectVar is supporting the selector natively, instead using the widget as "workaround"
But I would as expect that it works with the APISelectMultiple widget.

Observed Behavior

The selector works, but if something is selected from the selector its not get append the to the MultiObjectVar, if I use APISelect instead, the interface gets appended, but obviously its than a single object.

Originally created by @FloSch-Nokia on GitHub (Jul 10, 2023). ### NetBox version v3.5.5 ### Python version 3.10 ### Steps to Reproduce Create a custom script like this: ``` import string import json from django.contrib.contenttypes.models import ContentType from dcim.choices import DeviceFaceChoices, DeviceStatusChoices, CableTypeChoices, InterfaceTypeChoices from dcim.models import Cable, Device, DeviceRole, DeviceType, FrontPort, Interface, Manufacturer, Site, Platform, PowerPort, PowerOutlet, Rack from ipam.models import VLAN from extras.scripts import * from django.conf import settings from tenancy.models import Tenant from django import forms from utilities.forms.fields import * from utilities.forms.widgets import APISelect, APISelectMultiple, HTMXSelect class NewMacVrf(Script): class Meta: name = "New mac-vrf" description = "Add a mac-vrf" #field_order = ['macvrf_id', 'description', 'interfaces', 'vlan'] ### others objects removed interfaces_multi= MultiObjectVar( description="Interfaces", model=Interface, widget=APISelectMultiple( api_url='/api/dcim/interfaces/', attrs={'selector' : 'dcim.interface'}, ) ) def run(self, data, commit): output = [] for key, value in data.items(): output.append(f"{key}: {value}") return '\n'.join(output) ``` ![image](https://github.com/netbox-community/netbox/assets/24247464/ffa50b18-9bde-433d-b5d4-3ea0df79a4ed) The selector works, but if something is selected from the selector its not get append the to the MultiObjectVar, if I use APISelect instead, the interface gets appended, but obviously its than a single object. ### Expected Behavior Actually I would expect that MultiObjectVar is supporting the selector natively, instead using the widget as "workaround" But I would as expect that it works with the APISelectMultiple widget. ### Observed Behavior The selector works, but if something is selected from the selector its not get append the to the MultiObjectVar, if I use APISelect instead, the interface gets appended, but obviously its than a single object.
adam closed this issue 2025-12-29 20:35:13 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Jul 10, 2023):

Thank you for your report, however I'm afraid I don't see how this can be classified as a bug. The selector hasn't been implemented for multiple choice fields and core netbox doesn't use it for multiple choice fields yet. I guess it could be raised as a FR instead to add native support for the selector argument to both MultiObjectVar and ObjectVar, so feel free to do that.

There's also an issue somewhere, but I can't find it, where @jeremystretch mentioned that the object selector hasn't been implemented for multiple choice fields yet. Might be worth looking for as a way to get this implemented.

@kkthxbye-code commented on GitHub (Jul 10, 2023): Thank you for your report, however I'm afraid I don't see how this can be classified as a bug. The selector hasn't been implemented for multiple choice fields and core netbox doesn't use it for multiple choice fields yet. I guess it could be raised as a FR instead to add native support for the selector argument to both MultiObjectVar and ObjectVar, so feel free to do that. There's also an issue somewhere, but I can't find it, where @jeremystretch mentioned that the object selector hasn't been implemented for multiple choice fields yet. Might be worth looking for as a way to get this implemented.
Author
Owner

@abhi1693 commented on GitHub (Jul 10, 2023):

Here is the comment that @kkthxbye-code was referring to https://github.com/netbox-community/netbox/issues/11771#issuecomment-1533680229

@abhi1693 commented on GitHub (Jul 10, 2023): Here is the comment that @kkthxbye-code was referring to https://github.com/netbox-community/netbox/issues/11771#issuecomment-1533680229
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8312