Skip to content

Commit 2e5f04e

Browse files
committed
Raise an error rather than relying on Snuba telling us
1 parent 505ac16 commit 2e5f04e

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/sentry/search/events/builder/discover.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
from sentry.utils.dates import outside_retention_with_modified_start
7575
from sentry.utils.snuba import (
7676
QueryOutsideRetentionError,
77+
UnqualifiedQueryError,
7778
is_duration_measurement,
7879
is_measurement,
7980
is_numeric_measurement,
@@ -583,17 +584,17 @@ def resolve_params(self) -> list[WhereType]:
583584
if self.end:
584585
conditions.append(Condition(self.column("timestamp"), Op.LT, self.end))
585586

586-
# The clause will prevent calling Snuba with an empty list of projects, thus, returning
587-
# no data. It will not instead complain with:
588-
# sentry.utils.snuba.UnqualifiedQueryError: validation failed for entity events: missing required conditions for project_id
589-
if self.params.project_ids:
590-
conditions.append(
591-
Condition(
592-
self.column("project_id"),
593-
Op.IN,
594-
self.params.project_ids,
595-
)
587+
# This will prevent calling Snuba with an empty list of projects, thus, returning no data.
588+
if not self.params.project_ids:
589+
raise UnqualifiedQueryError("You need to specify at least one project.")
590+
591+
conditions.append(
592+
Condition(
593+
self.column("project_id"),
594+
Op.IN,
595+
self.params.project_ids,
596596
)
597+
)
597598

598599
if len(self.params.environments) > 0:
599600
term = event_search.SearchFilter(

tests/sentry/search/events/builder/test_discover.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_simple_query(self):
6868
)
6969
query.get_snql_query().validate()
7070

71-
def test_query_without_project_ids(self):
71+
def test_project_ids_missing(self):
7272
params: ParamsType = {
7373
"start": self.params["start"],
7474
"end": self.params["end"],
@@ -78,7 +78,7 @@ def test_query_without_project_ids(self):
7878
query = QueryBuilder(Dataset.Discover, params, query="foo", selected_columns=["id"])
7979
bulk_snuba_queries([query.get_snql_query()], referrer=Referrer.TESTING_TEST.value)
8080

81-
def test_query_with_empty_project_ids(self):
81+
def test_project_ids_with_empty_list(self):
8282
params: ParamsType = {
8383
"start": self.params["start"],
8484
"end": self.params["end"],

0 commit comments

Comments
 (0)