-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
status: 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
Description
NetBox version
v3.2.1
Python version
3.9
Steps to Reproduce
Create a Script with MultiObjectVar field
Set null_option='Any'
env_aggregate = MultiObjectVar(
label = "Aggregate",
model = Aggregate,
null_option = 'All',
required = False,
Run the script through the 'manage runscript' without providing any data.
Expected Behavior
Script runs fine
Observed Behavior
A TypeError is raised in DynamicModelMultipleChoiceField.clean()
netbox/netbox/utilities/forms/fields/dynamic.py
Lines 125 to 140 in f6402a8
| class DynamicModelMultipleChoiceField(DynamicModelChoiceMixin, forms.ModelMultipleChoiceField): | |
| """ | |
| A multiple-choice version of `DynamicModelChoiceField`. | |
| """ | |
| filter = django_filters.ModelMultipleChoiceFilter | |
| widget = widgets.APISelectMultiple | |
| def clean(self, value): | |
| """ | |
| When null option is enabled and "None" is sent as part of a form to be submitted, it is sent as the | |
| string 'null'. This will check for that condition and gracefully handle the conversion to a NoneType. | |
| """ | |
| if self.null_option is not None and settings.FILTERS_NULL_CHOICE_VALUE in value: | |
| value = [v for v in value if v != settings.FILTERS_NULL_CHOICE_VALUE] | |
| return [None, *value] | |
| return super().clean(value) |
The 'clean(self , value) gets the the 'value' parameter as 'None', if no data is passed to the script.
The 'in value' fails, as "argument of type 'NoneType' is not iterable"
Metadata
Metadata
Assignees
Labels
status: 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