Преглед изворни кода

Fixes #21049: Remove stale custom field data during object validation

Jeremy Stretch пре 1 месец
родитељ
комит
bc26529be8
1 измењених фајлова са 5 додато и 4 уклоњено
  1. 5 4
      netbox/netbox/models/features.py

+ 5 - 4
netbox/netbox/models/features.py

@@ -288,12 +288,13 @@ class CustomFieldsMixin(models.Model):
             cf.name: cf for cf in CustomField.objects.get_for_model(self)
             cf.name: cf for cf in CustomField.objects.get_for_model(self)
         }
         }
 
 
+        # Remove any stale custom field data
+        self.custom_field_data = {
+            k: v for k, v in self.custom_field_data.items() if k in custom_fields.keys()
+        }
+
         # Validate all field values
         # Validate all field values
         for field_name, value in self.custom_field_data.items():
         for field_name, value in self.custom_field_data.items():
-            if field_name not in custom_fields:
-                raise ValidationError(_("Unknown field name '{name}' in custom field data.").format(
-                    name=field_name
-                ))
             try:
             try:
                 custom_fields[field_name].validate(value)
                 custom_fields[field_name].validate(value)
             except ValidationError as e:
             except ValidationError as e: