Skip to content

Commit 1c2cf11

Browse files
abhi1693jeremystretch
authored andcommitted
fixes global search when the content type is not found #13507
1 parent 08961e7 commit 1c2cf11

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

netbox/utilities/fields.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def get_prefetch_queryset(self, instances, queryset=None):
103103
# We avoid looking for values if either ct_id or fkey value is None
104104
ct_id = getattr(instance, ct_attname)
105105
if ct_id is not None:
106+
# Check if the content type actually exists
107+
if not self.get_content_type(id=ct_id, using=instance._state.db).model_class():
108+
continue
109+
106110
fk_val = getattr(instance, self.fk_field)
107111
if fk_val is not None:
108112
fk_dict[ct_id].add(fk_val)
@@ -127,13 +131,14 @@ def gfk_key(obj):
127131
if ct_id is None:
128132
return None
129133
else:
130-
model = self.get_content_type(
134+
if model := self.get_content_type(
131135
id=ct_id, using=obj._state.db
132-
).model_class()
133-
return (
134-
model._meta.pk.get_prep_value(getattr(obj, self.fk_field)),
135-
model,
136-
)
136+
).model_class():
137+
return (
138+
model._meta.pk.get_prep_value(getattr(obj, self.fk_field)),
139+
model,
140+
)
141+
return None
137142

138143
return (
139144
ret_val,

0 commit comments

Comments
 (0)