Skip to content

Commit 6361b3a

Browse files
sentry[bot]cvxluofrifri
authored
fix(issues): Return 400 for InvalidSearchQuery during bulk delete and update (#128414)
When a bulk issue delete or update request contains an invalid search query—for example `?query=issue:155261377` where a numeric group id is passed to the `issue:` filter instead of a qualified short id—`format_search_filter` raises an `InvalidSearchQuery` while building the Snuba query. Because this happens inside `search_fn` rather than `parse_and_convert_issue_search_query`, the exception was not translated to a `ValidationError`. Both `schedule_tasks_to_delete_groups` and `update_groups_with_search_fn` only caught `ValidationError`, allowing `InvalidSearchQuery` to bubble up to the top-level endpoint exception handler, which logged an error traceback and returned HTTP 500. This change: - Catches `InvalidSearchQuery` in `schedule_tasks_to_delete_groups` and returns an HTTP 400 response with `{"detail": "Invalid search query."}`. - Catches `InvalidSearchQuery` in `update_groups_with_search_fn` and returns an HTTP 400 response with `{"detail": "Invalid search query."}` without logging an error to Sentry. - Uses a generic client-safe error message rather than echoing exception internals into the response. <!-- Sentry employees and contractors can delete or ignore the following. --> ### Legal Boilerplate Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. <!-- SEER_FIXES_SENTRY_ISSUE --> Fixes [SENTRY-5Z50](https://sentry.sentry.io/issues/7805127888/?seerDrawer=true) <!-- /SEER_FIXES_SENTRY_ISSUE --> <sub>`@sentry <feedback>`: Autofix iterates on these changes</sub> <sub>`@sentry stop iterating`: Autofix stops iterating on this run</sub> --------- Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com> Co-authored-by: cvxluo <27893746+cvxluo@users.noreply.github.com> Co-authored-by: Charlie Luo <cvxluo@gmail.com> Co-authored-by: Francis Genet <francis.genet@gmail.com>
1 parent 3a31e48 commit 6361b3a

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎src/sentry/api/helpers/group_index/delete.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from sentry.apidocs.response_types import ValidationErrorResponse
1919
from sentry.deletions.defaults.group import GROUP_CHUNK_SIZE
2020
from sentry.deletions.tasks.groups import delete_groups_for_project
21+
from sentry.exceptions import InvalidSearchQuery
2122
from sentry.models.group import Group, GroupStatus
2223
from sentry.models.groupinbox import GroupInbox
2324
from sentry.models.project import Project
@@ -187,6 +188,8 @@ def schedule_tasks_to_delete_groups(
187188
)
188189
except ValidationError as exc:
189190
return Response({"detail": str(exc)}, status=400)
191+
except InvalidSearchQuery:
192+
return Response({"detail": "Invalid search query."}, status=400)
190193

191194
group_list = list(cursor_result)
192195

‎src/sentry/api/helpers/group_index/update.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from sentry.api.serializers import serialize
2424
from sentry.api.serializers.models.actor import ActorSerializer, ActorSerializerResponse
2525
from sentry.api.serializers.models.groupactionlogentry import get_serialized_activity_items
26+
from sentry.exceptions import InvalidSearchQuery
2627
from sentry.hybridcloud.rpc import coerce_id_from
2728
from sentry.integrations.tasks.kick_off_status_syncs import kick_off_status_syncs
2829
from sentry.issues.action_log import (
@@ -332,6 +333,10 @@ def update_groups_with_search_fn(
332333
return Response(
333334
{"detail": "Invalid query. Error getting group ids and group list"}, status=400
334335
)
336+
except InvalidSearchQuery:
337+
# Raised while building the Snuba query (e.g. `issue:` with an
338+
# invalid short ID). This is a client error; don't report it.
339+
return Response({"detail": "Invalid search query."}, status=400)
335340

336341
group_list = list(cursor_result)
337342

0 commit comments

Comments
 (0)