Skip to content

Commit

Permalink
fix keyerror happening when searching non existing fields (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricOuma authored Mar 14, 2024
1 parent ccbe80b commit 79164e6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion django_typesense/changelist.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from django import forms
from django.contrib import messages
from django.contrib.admin.exceptions import DisallowedModelAdminToField
Expand Down Expand Up @@ -32,6 +34,8 @@
TO_FIELD_VAR,
)

logger = logging.getLogger(__name__)


class ChangeListSearchForm(forms.Form):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -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 == "":
Expand Down

0 comments on commit 79164e6

Please sign in to comment.