From 79164e6af68a03e8b730e6d8f80a2b3ec43813f4 Mon Sep 17 00:00:00 2001 From: ERIC OUMA Date: Thu, 14 Mar 2024 15:21:08 +0300 Subject: [PATCH] fix keyerror happening when searching non existing fields (#83) --- django_typesense/changelist.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/django_typesense/changelist.py b/django_typesense/changelist.py index e893106..6c8bda1 100644 --- a/django_typesense/changelist.py +++ b/django_typesense/changelist.py @@ -1,3 +1,5 @@ +import logging + from django import forms from django.contrib import messages from django.contrib.admin.exceptions import DisallowedModelAdminToField @@ -32,6 +34,8 @@ TO_FIELD_VAR, ) +logger = logging.getLogger(__name__) + class ChangeListSearchForm(forms.Form): def __init__(self, *args, **kwargs): @@ -255,7 +259,13 @@ def get_search_filters(self, field_name: str, used_parameters: dict): } max_val, min_val, lookup, value = None, None, None, None - field = self.model.collection_class.get_field(field_name) + try: + field = self.model.collection_class.get_field(field_name) + except KeyError as er: + logger.debug( + f"Searching `{field_name}` with parameters `{used_parameters}` produced error: {er}" + ) + return search_filters_dict for key, value in used_parameters.items(): if value is None or value == "":