Merge pull request #20037 from netbox-community/19988-has_feature-invalid-objecttype
Some checks are pending
CI / build (20.x, 3.10) (push) Waiting to run
CI / build (20.x, 3.11) (push) Waiting to run
CI / build (20.x, 3.12) (push) Waiting to run

Fixes #19988: `has_feature()` should gracefully handle invalid ContentTypes
This commit is contained in:
bctiemann 2025-08-07 20:50:32 -04:00 committed by GitHub
commit ab8e3ee956
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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