Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
FloSch-Nokia opened this issue Jul 10, 2023 · 2 comments

Comments

@FloSch-Nokia
Copy link

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.

@FloSch-Nokia FloSch-Nokia added the type: bug A confirmed report of unexpected behavior in the application label Jul 10, 2023
@kkthxbye-code
Copy link
Contributor

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 kkthxbye-code closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2023
@kkthxbye-code kkthxbye-code removed the type: bug A confirmed report of unexpected behavior in the application label Jul 10, 2023
@abhi1693
Copy link
Member

Here is the comment that @kkthxbye-code was referring to #11771 (comment)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants