Skip to content

Commit

Permalink
Handle errors when filtering columns with special characters (#4511)
Browse files Browse the repository at this point in the history
* eeej small files

* catch error on special character columns

* variable assignment

* handle special characters:
  • Loading branch information
perryr16 authored Jan 31, 2024
1 parent c8a8e06 commit 84908ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 18 additions & 1 deletion seed/utils/inventory_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion seed/utils/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

0 comments on commit 84908ef

Please sign in to comment.