Skip to content

Commit

Permalink
fixes global search when the content type is not found #13507
Browse files Browse the repository at this point in the history
  • Loading branch information
abhi1693 authored and jeremystretch committed Aug 24, 2023
1 parent 08961e7 commit 1c2cf11
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions netbox/utilities/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def get_prefetch_queryset(self, instances, queryset=None):
# We avoid looking for values if either ct_id or fkey value is None
ct_id = getattr(instance, ct_attname)
if ct_id is not None:
# Check if the content type actually exists
if not self.get_content_type(id=ct_id, using=instance._state.db).model_class():
continue

fk_val = getattr(instance, self.fk_field)
if fk_val is not None:
fk_dict[ct_id].add(fk_val)
Expand All @@ -127,13 +131,14 @@ def gfk_key(obj):
if ct_id is None:
return None
else:
model = self.get_content_type(
if model := self.get_content_type(
id=ct_id, using=obj._state.db
).model_class()
return (
model._meta.pk.get_prep_value(getattr(obj, self.fk_field)),
model,
)
).model_class():
return (
model._meta.pk.get_prep_value(getattr(obj, self.fk_field)),
model,
)
return None

return (
ret_val,
Expand Down

0 comments on commit 1c2cf11

Please sign in to comment.