Arthur 18 godzin temu
rodzic
commit
8d462b7b02

+ 5 - 1
netbox/extras/forms/bulk_import.py

@@ -317,7 +317,6 @@ class EventRuleImportForm(OwnerCSVMixin, NetBoxModelImportForm):
         help_text=_("One or more assigned object types")
     )
     event_types = CSVMultipleChoiceField(
-        choices=get_event_type_choices,
         label=_('Event types'),
         help_text=_('The event type(s) which will trigger this rule')
     )
@@ -337,6 +336,11 @@ class EventRuleImportForm(OwnerCSVMixin, NetBoxModelImportForm):
             'owner', 'comments', 'tags'
         )
 
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        # Resolved per instance because plugins register event types after this module is imported
+        self.fields['event_types'].choices = get_event_type_choices()
+
     def clean(self):
         super().clean()
 

+ 1 - 5
netbox/utilities/forms/fields/csv.py

@@ -37,11 +37,7 @@ class CSVChoicesMixin:
 
     def __init__(self, *, choices=(), **kwargs):
         super().__init__(choices=choices, **kwargs)
-        # Keep callable choices lazy so they're resolved on each access
-        if callable(choices):
-            self.choices = lambda: unpack_grouped_choices(choices())
-        else:
-            self.choices = unpack_grouped_choices(choices)
+        self.choices = unpack_grouped_choices(choices)
 
 
 class CSVChoiceField(CSVChoicesMixin, forms.ChoiceField):