From 5c1463a77d32a399f49f50f2cb046d7e3dc539b5 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Mon, 17 Oct 2022 13:20:46 -0400 Subject: [PATCH] Avoid calling remove() on non-cacheable objects --- netbox/netbox/search/backends.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/netbox/netbox/search/backends.py b/netbox/netbox/search/backends.py index 82c1fa452..fbd9a83a7 100644 --- a/netbox/netbox/search/backends.py +++ b/netbox/netbox/search/backends.py @@ -87,6 +87,11 @@ class SearchBackend: """ Receiver for the post_delete signal, responsible for caching object deletion. """ + try: + get_indexer(instance) + except KeyError: + # Avoid attempting to query for non-cacheable objects + return cls.remove(instance) @classmethod @@ -193,7 +198,7 @@ class CachedValueSearchBackend(SearchBackend): ct = ContentType.objects.get_for_model(instance) # Wipe out any previously cached values for the object - CachedValue.objects.filter(object_type=ct, object_id=instance.pk).delete() + cls.remove(instance) # Record any new non-empty values cached_values = []