From 830b56ac9ef014b037b1a6c81c87219c69848667 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 5 Apr 2022 08:40:30 -0400 Subject: [PATCH] Check that ChoiceSet CHOICES is mutable if key is set --- netbox/utilities/choices.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/netbox/utilities/choices.py b/netbox/utilities/choices.py index 62f6837ec..c5b5bafb9 100644 --- a/netbox/utilities/choices.py +++ b/netbox/utilities/choices.py @@ -9,6 +9,7 @@ class ChoiceSetMeta(type): # Extend static choices with any configured choices if key := attrs.get('key'): + assert type(attrs['CHOICES']) is list, f"{name} has a key defined but CHOICES is not a list" app = attrs['__module__'].split('.', 1)[0] replace_key = f'{app}.{key}' extend_key = f'{replace_key}+' if replace_key else None @@ -47,7 +48,7 @@ class ChoiceSetMeta(type): class ChoiceSet(metaclass=ChoiceSetMeta): """ - Holds an interable of choice tuples suitable for passing to a Django model or form field. Choices can be defined + Holds an iterable of choice tuples suitable for passing to a Django model or form field. Choices can be defined statically within the class as CHOICES and/or gleaned from the FIELD_CHOICES configuration parameter. """ CHOICES = list()