diff --git a/seed/utils/inventory_filter.py b/seed/utils/inventory_filter.py index 87009b7217..b524e73e96 100644 --- a/seed/utils/inventory_filter.py +++ b/seed/utils/inventory_filter.py @@ -146,7 +146,16 @@ def get_filtered_results(request: Request, inventory_type: Literal['property', ' status=status.HTTP_400_BAD_REQUEST ) - views_list = views_list.annotate(**annotations).filter(filters).order_by(*order_by) + try: + views_list = views_list.annotate(**annotations).filter(filters).order_by(*order_by) + except ValueError as e: + return JsonResponse( + { + 'stauts': 'error', + 'message': f'Error filtering: {str(e)}' + }, + status=status.HTTP_400_BAD_REQUEST + ) # If we are returning the children, build the childrens filters. if include_related: @@ -217,6 +226,14 @@ def get_filtered_results(request: Request, inventory_type: Literal['property', ' }, status=status.HTTP_400_BAD_REQUEST ) + except IndexError as e: + return JsonResponse( + { + 'status': 'error', + 'message': f'Error filtering - Clear filters and try again: {str(e)}' + }, + status=status.HTTP_400_BAD_REQUEST + ) try: related_results = TaxLotProperty.serialize( diff --git a/seed/utils/search.py b/seed/utils/search.py index 9adf8b7532..723ba0f3ef 100644 --- a/seed/utils/search.py +++ b/seed/utils/search.py @@ -273,7 +273,10 @@ def _build_extra_data_annotations(column_name: str, data_type: str) -> tuple[str .replace("'", '-') \ .replace('"', '-') \ .replace('`', '-') \ - .replace(';', '-') + .replace(';', '-') \ + .replace('[', '_') \ + .replace(']', '_') \ + .replace('%', '_') text_field_name = f'_{cleaned_column_name}_to_text' final_field_name = f'_{cleaned_column_name}_final'