From 0d2a8b8b859599e8f83f5a6a7c2f40973cb7ff81 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Mar 2025 17:11:37 -0400 Subject: [PATCH] Ensure deterministic ordering of attriubte fields --- netbox/dcim/forms/model_forms.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/netbox/dcim/forms/model_forms.py b/netbox/dcim/forms/model_forms.py index a8fcfd8e8..44703d1a0 100644 --- a/netbox/dcim/forms/model_forms.py +++ b/netbox/dcim/forms/model_forms.py @@ -489,15 +489,16 @@ class ModuleTypeForm(NetBoxModelForm): prop = JSONSchemaProperty(**options) attr_fields[name] = prop.to_form_field(name, required=name in required_fields) - return attr_fields + return dict(sorted(attr_fields.items())) def _post_clean(self): # Compile attribute data from the individual form fields - self.instance.attribute_data = { - name[5:]: self.cleaned_data[name] # Remove the attr_ prefix - for name in self.attr_fields if self.cleaned_data[name] is not None - } + if self.cleaned_data.get('profile'): + self.instance.attribute_data = { + name[5:]: self.cleaned_data[name] # Remove the attr_ prefix + for name in self.attr_fields if self.cleaned_data[name] is not None + } return super()._post_clean()