diff --git a/src/sentry/api/endpoints/organization_events.py b/src/sentry/api/endpoints/organization_events.py index c7553bebde7a47..41cfb3cbf2a251 100644 --- a/src/sentry/api/endpoints/organization_events.py +++ b/src/sentry/api/endpoints/organization_events.py @@ -63,6 +63,9 @@ def data_fn(offset, limit): auto_fields=True, auto_aggregations=True, use_aggregate_conditions=True, + use_snql=features.has( + "organizations:discover-use-snql", organization, actor=request.user + ), ) with self.handle_query_errors(): diff --git a/tests/snuba/api/endpoints/test_organization_events_v2.py b/tests/snuba/api/endpoints/test_organization_events_v2.py index 381f48352a67ed..3f1d99175fcb2f 100644 --- a/tests/snuba/api/endpoints/test_organization_events_v2.py +++ b/tests/snuba/api/endpoints/test_organization_events_v2.py @@ -41,10 +41,12 @@ def setUp(self): self.min_ago = iso_format(before_now(minutes=1)) self.two_min_ago = iso_format(before_now(minutes=2)) self.transaction_data = load_data("transaction", timestamp=before_now(minutes=1)) + self.features = {} def do_request(self, query, features=None): if features is None: features = {"organizations:discover-basic": True} + features.update(self.features) self.login_as(user=self.user) url = reverse( "sentry-api-0-organization-eventsv2", @@ -133,8 +135,10 @@ def test_invalid_search_terms(self): ) @mock.patch("sentry.snuba.discover.raw_query") - def test_handling_snuba_errors(self, mock_query): + @mock.patch("sentry.snuba.discover.raw_snql_query") + def test_handling_snuba_errors(self, mock_snql_query, mock_query): mock_query.side_effect = RateLimitExceeded("test") + mock_snql_query.side_effect = RateLimitExceeded("test") project = self.create_project() @@ -148,6 +152,7 @@ def test_handling_snuba_errors(self, mock_query): assert response.data["detail"] == TIMEOUT_ERROR_MESSAGE mock_query.side_effect = QueryExecutionError("test") + mock_snql_query.side_effect = QueryExecutionError("test") query = {"field": ["id", "timestamp"], "orderby": ["-timestamp", "-id"]} response = self.do_request(query) @@ -155,6 +160,7 @@ def test_handling_snuba_errors(self, mock_query): assert response.data["detail"] == "Internal error. Your query failed to run." mock_query.side_effect = QueryIllegalTypeOfArgument("test") + mock_snql_query.side_effect = QueryIllegalTypeOfArgument("test") query = {"field": ["id", "timestamp"], "orderby": ["-timestamp", "-id"]} response = self.do_request(query) @@ -1412,6 +1418,7 @@ def test_user_misery_alias_field_with_project_threshold(self): "transaction", "user_misery()", ], + "orderby": "user_misery()", "query": "event.type:transaction", "project": [project.id], } @@ -1422,8 +1429,8 @@ def test_user_misery_alias_field_with_project_threshold(self): assert len(response.data["data"]) == 3 data = response.data["data"] assert abs(data[0]["user_misery"] - 0.04916) < 0.0001 - assert abs(data[1]["user_misery"] - 0.06586) < 0.0001 - assert abs(data[2]["user_misery"] - 0.05751) < 0.0001 + assert abs(data[1]["user_misery"] - 0.05751) < 0.0001 + assert abs(data[2]["user_misery"] - 0.06586) < 0.0001 query["query"] = "event.type:transaction user_misery():>0.050" @@ -1434,8 +1441,8 @@ def test_user_misery_alias_field_with_project_threshold(self): assert response.status_code == 200, response.content assert len(response.data["data"]) == 2 data = response.data["data"] - assert abs(data[0]["user_misery"] - 0.06586) < 0.0001 - assert abs(data[1]["user_misery"] - 0.05751) < 0.0001 + assert abs(data[0]["user_misery"] - 0.05751) < 0.0001 + assert abs(data[1]["user_misery"] - 0.06586) < 0.0001 def test_user_misery_alias_field_with_transaction_threshold(self): project = self.create_project() @@ -3166,14 +3173,14 @@ def test_deleted_issue_in_results(self): event2.group.delete() features = {"organizations:discover-basic": True, "organizations:global-views": True} - query = {"field": ["issue", "count()"], "sort": "issue"} + query = {"field": ["issue", "count()"], "sort": "count()"} response = self.do_request(query, features=features) assert response.status_code == 200, response.content data = response.data["data"] assert len(data) == 2 - assert data[0]["issue"] == event1.group.qualified_short_id - assert data[1]["issue"] == "unknown" + assert data[0]["issue"] == "unknown" + assert data[1]["issue"] == event1.group.qualified_short_id def test_last_seen_negative_duration(self): project = self.create_project() @@ -4473,3 +4480,9 @@ def test_mobile_measurements(self): assert meta["p75_measurements_stall_percentage"] == "percentage" assert meta["percentile_measurements_frames_slow_rate_0_5"] == "percentage" assert meta["percentile_measurements_stall_percentage_0_5"] == "percentage" + + +class OrganizationEventsV2EndpointTestWithSnql(OrganizationEventsV2EndpointTest): + def setUp(self): + super().setUp() + self.features["organizations:discover-use-snql"] = True