-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Utility function get_field_value returns last value when used on a multi-value field #17794
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
Comments
This is expected (but annoying) behaviour as per: https://code.djangoproject.com/ticket/1130 Two options are possible:
|
Proposed rewrite:
|
@DanSheps to submit a PR per maintainers meeting |
@DanSheps could you please rewrite the original issue to include reproduction steps? I'm not able to reproduce this: >>> from django.http import QueryDict
>>> from utilities.forms import get_field_value
>>> from dcim.forms import InterfaceForm
>>>
>>> qd = QueryDict("mode=tagged&tagged_vlans=2&tagged_vlans=27")
>>> f = InterfaceForm(initial=qd)
>>> get_field_value(f, 'tagged_vlans')
['2', '27'] |
After re-reviewing the code, I realised I made an error before trying to fix this: On March 31st, when fixing another issue, the code around this function changed from: if form.is_bound and (data := form.data.get(field_name)):
if hasattr(field, 'valid_value') and field.valid_value(data):
return data to if form.is_bound and field_name in form.data:
if (value := form.data[field_name]) is None:
return
if hasattr(field, 'valid_value') and field.valid_value(value):
return value This slight change in code seems to have resolved the issue fully as we are no longer using |
Fixed by: #19023 |
Deployment Type
Self-hosted
Triage priority
I volunteer to perform this work (if approved)
NetBox Version
v4.1.4
Python Version
3.10
Steps to Reproduce
tagged_vlans
)Expected Behavior
get_field_value to return multiple values
Observed Behavior
get_field_valueu returns a single value
The text was updated successfully, but these errors were encountered: