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

Aperta Adatta ai principianti
#94 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia da views/scripts.py:148 e confronta il modo in cui il plugin crea i dati iniziali del modulo con l’uso di normalize_querydict nel core di NetBox in extras/views.py:1727. Esegui il test della view che renderizza la pagina di esecuzione dello script con parametri tags ripetuti. Il lavoro è concluso quando sono selezionati entrambi gli ID dei tag, non solo l’ultimo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
8
Fork
0
Merge medio
11h 23m
PR unite (30g)
24

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di netbox-community/netbox-scripts

Tutte le issue di netbox-community/netbox-scripts

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.