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

Merge pull request #20037 from netbox-community/19988-has_feature-invalid-objecttype

Fixes #19988: `has_feature()` should gracefully handle invalid ContentTypes
bctiemann пре 6 месеци
родитељ
комит
ab8e3ee956
1 измењених фајлова са 5 додато и 1 уклоњено
  1. 5 1
      netbox/netbox/models/features.py

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

@@ -679,10 +679,14 @@ def has_feature(model_or_ct, feature):
         ot = model_or_ct
     # If a ContentType was passed, resolve its model class
     elif type(model_or_ct) is ContentType:
-        ot = ObjectType.objects.get_for_model(model_or_ct.model_class())
+        model_class = model_or_ct.model_class()
+        ot = ObjectType.objects.get_for_model(model_class) if model_class else None
     # For anything else, look up the ObjectType
     else:
         ot = ObjectType.objects.get_for_model(model_or_ct)
+    # ObjectType is invalid/deleted
+    if ot is None:
+        return False
     return feature in ot.features