-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Labels
severity: mediumResults in substantial degraded or broken functionality for specfic workflowsResults in substantial degraded or broken functionality for specfic workflowsstatus: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application
Milestone
Description
Deployment Type
Self-hosted
NetBox Version
v4.2.6
Python Version
3.10
Steps to Reproduce
This was uncovered while using the get_field_value()
utility function for dynamic form rendering. A simple proof is provided below.
from django import forms
from dcim.models import Site
from utilities.forms.utils import get_field_value
class MyForm(forms.Form):
site = forms.ModelChoiceField(
queryset=Site.objects.all(),
required=False
)
form = MyForm({'site': None}, initial={'site': 1})
get_field_value(form, 'site')
Expected Behavior
The function should always return the value of the field in a bound form.
Observed Behavior
When a null value is specified on a bound form, the function defers to the field's initial value:
>>> form = MyForm({'site': 2}, initial={'site': 1})
>>> get_field_value(form, 'site')
2
>>> form = MyForm({'site': None}, initial={'site': 1})
>>> get_field_value(form, 'site')
1
Metadata
Metadata
Assignees
Labels
severity: mediumResults in substantial degraded or broken functionality for specfic workflowsResults in substantial degraded or broken functionality for specfic workflowsstatus: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application