Browse Source

17406 allow deletion of plugin custom field if plugin removed

Arthur Hanson 1 year ago
parent
commit
48ca5d4d7e
1 changed files with 5 additions and 4 deletions
  1. 5 4
      netbox/extras/models/customfields.py

+ 5 - 4
netbox/extras/models/customfields.py

@@ -295,10 +295,11 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
         """
         for ct in content_types:
             model = ct.model_class()
-            instances = model.objects.filter(custom_field_data__has_key=self.name)
-            for instance in instances:
-                del instance.custom_field_data[self.name]
-            model.objects.bulk_update(instances, ['custom_field_data'], batch_size=100)
+            if model:
+                instances = model.objects.filter(custom_field_data__has_key=self.name)
+                for instance in instances:
+                    del instance.custom_field_data[self.name]
+                model.objects.bulk_update(instances, ['custom_field_data'], batch_size=100)
 
     def rename_object_data(self, old_name, new_name):
         """