فهرست منبع

Fixes #9291: Improve data validation for MultiObjectVar script fields

jeremystretch 3 سال پیش
والد
کامیت
b0a56a71bb
2فایلهای تغییر یافته به همراه6 افزوده شده و 4 حذف شده
  1. 1 0
      docs/release-notes/version-3.2.md
  2. 5 4
      netbox/utilities/forms/fields/dynamic.py

+ 1 - 0
docs/release-notes/version-3.2.md

@@ -16,6 +16,7 @@
 ### Bug Fixes
 ### Bug Fixes
 
 
 * [#9094](https://github.com/netbox-community/netbox/issues/9094) - Fix partial address search within Prefix and Aggregate filters
 * [#9094](https://github.com/netbox-community/netbox/issues/9094) - Fix partial address search within Prefix and Aggregate filters
+* [#9291](https://github.com/netbox-community/netbox/issues/9291) - Improve data validation for MultiObjectVar script fields
 * [#9358](https://github.com/netbox-community/netbox/issues/9358) - Annotate circuit count for providers list under ASN view
 * [#9358](https://github.com/netbox-community/netbox/issues/9358) - Annotate circuit count for providers list under ASN view
 * [#9387](https://github.com/netbox-community/netbox/issues/9387) - Ensure ActionsColumn `extra_buttons` are always displayed
 * [#9387](https://github.com/netbox-community/netbox/issues/9387) - Ensure ActionsColumn `extra_buttons` are always displayed
 * [#9402](https://github.com/netbox-community/netbox/issues/9402) - Fix custom field population when creating a virtual chassis
 * [#9402](https://github.com/netbox-community/netbox/issues/9402) - Fix custom field population when creating a virtual chassis

+ 5 - 4
netbox/utilities/forms/fields/dynamic.py

@@ -135,11 +135,12 @@ class DynamicModelMultipleChoiceField(DynamicModelChoiceMixin, forms.ModelMultip
     widget = widgets.APISelectMultiple
     widget = widgets.APISelectMultiple
 
 
     def clean(self, value):
     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.
-        """
+        value = value or []
+
+        # 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:
         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]
             value = [v for v in value if v != settings.FILTERS_NULL_CHOICE_VALUE]
             return [None, *value]
             return [None, *value]
+
         return super().clean(value)
         return super().clean(value)