Skip to content

Commit 2ae98f0

Browse files
jnovingerjeremystretch
authored andcommitted
Fixes #20587: Handle stale ContentTypes in has_feature()
When deleting stale ContentTypes during remove_stale_contenttypes, the pre_delete signal triggers notify_object_changed(), which calls has_feature() with the ContentType instance. For stale types (those with no corresponding model class), model_class() returns None, which then gets passed to issubclass() in the feature test lambda, causing a TypeError. The previous implementation in has_feature() checked for None before attempting ObjectType lookup. The optimization in 5ceb6a6 removed this safety check when refactoring the ContentType code path to use direct feature registry lookups. This restores the null check to maintain the original behavior of returning False for stale ContentTypes.
1 parent addda05 commit 2ae98f0

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

netbox/netbox/models/features.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,8 @@ def has_feature(model_or_ct, feature):
676676
# If a ContentType was passed, resolve its model class and run the associated feature test
677677
elif type(model_or_ct) is ContentType:
678678
model = model_or_ct.model_class()
679+
if model is None: # Stale content type
680+
return False
679681
try:
680682
test_func = registry['model_features'][feature]
681683
except KeyError:

0 commit comments

Comments
 (0)