Skip to content

Commit 61312d2

Browse files
committed
Add tests
1 parent e566d18 commit 61312d2

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,9 @@ def resolve_params(self) -> list[WhereType]:
583583
if self.end:
584584
conditions.append(Condition(self.column("timestamp"), Op.LT, self.end))
585585

586-
# The if clause will prevent calling Snuba with an empty list of projects and complain with:
587-
# sentry.utils.snuba.SnubaError: validation failed for entity events: missing required conditions for project_id
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
588589
if self.params.project_ids:
589590
conditions.append(
590591
Condition(

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
from sentry.search.events.builder import QueryBuilder
1717
from sentry.search.events.types import ParamsType, QueryBuilderConfig
1818
from sentry.snuba.dataset import Dataset
19+
from sentry.snuba.referrer import Referrer
1920
from sentry.testutils.cases import TestCase
20-
from sentry.utils.snuba import QueryOutsideRetentionError
21+
from sentry.utils.snuba import QueryOutsideRetentionError, UnqualifiedQueryError, bulk_snuba_queries
2122
from sentry.utils.validators import INVALID_ID_DETAILS
2223

2324
pytestmark = pytest.mark.sentry_metrics
@@ -67,6 +68,27 @@ def test_simple_query(self):
6768
)
6869
query.get_snql_query().validate()
6970

71+
def test_query_without_project_ids(self):
72+
params = {
73+
"start": self.params["start"],
74+
"end": self.params["end"],
75+
"organization_id": self.organization.id,
76+
}
77+
with pytest.raises(UnqualifiedQueryError):
78+
query = QueryBuilder(Dataset.Discover, params, query="foo", selected_columns=["id"])
79+
bulk_snuba_queries([query.get_snql_query()], referrer=Referrer.TESTING_TEST.value)
80+
81+
def test_query_with_empty_project_ids(self):
82+
params = {
83+
"start": self.params["start"],
84+
"end": self.params["end"],
85+
"project_id": [], # We add an empty project_id list
86+
"organization_id": self.organization.id,
87+
}
88+
with pytest.raises(UnqualifiedQueryError):
89+
query = QueryBuilder(Dataset.Discover, params, query="foo", selected_columns=["id"])
90+
bulk_snuba_queries([query.get_snql_query()], referrer=Referrer.TESTING_TEST.value)
91+
7092
def test_simple_orderby(self):
7193
query = QueryBuilder(
7294
Dataset.Discover,

0 commit comments

Comments
 (0)