Skip to content

Commit

Permalink
Fix error where exception for missing vector is silenced.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgliss committed Dec 1, 2023
1 parent 5a88100 commit 9e69b68
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/dispatch/database/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ def build_filters(filter_spec):

if not _is_iterable_filter(fn_args):
raise BadFilterFormat(
"`{}` value must be an iterable across the function "
"arguments".format(boolean_function.key)
"`{}` value must be an iterable across the function " "arguments".format(
boolean_function.key
)
)
if boolean_function.only_one_arg and len(fn_args) != 1:
raise BadFilterFormat(
Expand Down Expand Up @@ -291,7 +292,7 @@ def apply_filters(query, filter_spec, model_cls=None, do_auto_join=True):
:param filter_spec:
A dict or an iterable of dicts, where each one includes
the necesary information to create a filter to be applied to the
the necessary information to create a filter to be applied to the
query.
Example::
Expand Down Expand Up @@ -337,7 +338,7 @@ def apply_filters(query, filter_spec, model_cls=None, do_auto_join=True):


def apply_filter_specific_joins(model: Base, filter_spec: dict, query: orm.query):
"""Applies any model specific implicity joins."""
"""Applies any model specific implicitly joins."""
# this is required because by default sqlalchemy-filter's auto-join
# knows nothing about how to join many-many relationships.
model_map = {
Expand Down Expand Up @@ -402,15 +403,19 @@ def search(*, query_str: str, query: Query, model: str, sort=False):
if not query_str.strip():
return query

vector = search_model.search_vector
if hasattr(search_model, "search_vector"):
vector = search_model.search_vector
query = query.filter(vector.op("@@")(func.tsq_parse(query_str)))

query = query.filter(
or_(
vector.op("@@")(func.tsq_parse(query_str)),
search_model.name.ilike(f"%{query_str}%"),
search_model.name == query_str,
elif hasattr(search_model, "name"):
query = query.filter(
or_(
search_model.name.ilike(f"%{query_str}%"),
search_model.name == query_str,
)
)
)
else:
raise Exception(f"Search not supported for model: {model}")

if sort:
query = query.order_by(desc(func.ts_rank_cd(vector, func.tsq_parse(query_str))))
Expand Down Expand Up @@ -523,8 +528,6 @@ def search_filter_sort_paginate(
raise ValidationError(
[ErrorWrapper(InvalidFilterError(msg=str(e)), loc="filter")], model=BaseModel
) from None
except Exception as e:
log.exception(e)

if items_per_page == -1:
items_per_page = None
Expand Down Expand Up @@ -555,7 +558,7 @@ def search_filter_sort_paginate(
def restricted_incident_filter(query: orm.Query, current_user: DispatchUser, role: UserRoles):
"""Adds additional incident filters to query (usually for permissions)."""
if role == UserRoles.member:
# We filter out resticted incidents for users with a member role if the user is not an incident participant
# We filter out restricted incidents for users with a member role if the user is not an incident participant
query = (
query.join(Participant, Incident.id == Participant.incident_id)
.join(IndividualContact)
Expand Down

0 comments on commit 9e69b68

Please sign in to comment.