Prefilling a MultiObjectVar from the Run URL keeps only the last ID

Open Beginner friendly
#94 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start at views/scripts.py:148 and compare how the plugin builds form initial data with NetBox core's normalize_querydict usage in extras/views.py:1727. Run the view test that renders the script run page with repeated tags parameters. Done means both tag IDs are selected, not just the last one.

Written by the indexing model from the issue text.

Description

app: scripts severity: low status: backlog type: bug
Plugin Version

v0.0.1 (also present on main)

NetBox Version

v4.7.4

Python Version

3.12

Steps to Reproduce
  1. Activate a Script with a MultiObjectVar:

    from extras.models import Tag
    from netbox_scripts import MultiObjectVar, Script
    
    
    class PickTags(Script):
        tags = MultiObjectVar(model=Tag)
    
        def run(self, data, commit):
            return ','.join(tag.name for tag in data['tags'])
    
  2. Create two tags (IDs 1 and 2 below).

  3. Open the Script's run view with both IDs in the URL: /plugins/netbox-scripts/scripts/<id>/run/?tags=1&tags=2.

Expected Behavior

Both tags are preselected, as they are for a built-in Script with the same URL.

Observed Behavior

Found while reviewing #86, which documents prefilling a selection from the Run URL.

Only tag 2 is preselected. With ?tags=1 alone, tag 1 is preselected as expected. Reproduced with a view test on NetBox v4.7.4 that renders the run page and reads the selected options.

views/scripts.py:148 builds the form with initial=request.GET.dict(), and QueryDict.dict() keeps only the last value of a repeated key. Core's script view uses normalize_querydict(request.GET) (extras/views.py:1727 in NetBox), and swapping that in makes the same test preselect both tags.

Dominant language
Python
Stars
8
Forks
0
Avg merge
11h 23m
Merged PRs (30d)
24

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from netbox-community/netbox-scripts

All issues in netbox-community/netbox-scripts

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.