Ensure deterministic ordering of attriubte fields

This commit is contained in:
Jeremy Stretch 2025-03-26 17:11:37 -04:00
parent c1ff89e98f
commit 0d2a8b8b85

View File

@ -489,15 +489,16 @@ class ModuleTypeForm(NetBoxModelForm):
prop = JSONSchemaProperty(**options) prop = JSONSchemaProperty(**options)
attr_fields[name] = prop.to_form_field(name, required=name in required_fields) 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): def _post_clean(self):
# Compile attribute data from the individual form fields # Compile attribute data from the individual form fields
self.instance.attribute_data = { if self.cleaned_data.get('profile'):
name[5:]: self.cleaned_data[name] # Remove the attr_ prefix self.instance.attribute_data = {
for name in self.attr_fields if self.cleaned_data[name] is not None 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() return super()._post_clean()