Browse Source

fix(discover): Check BooleanCondition in where clause (#29785)

Check for boolean condition in where clause so that
checking for top level project conditions doesn't
break.
Shruthi 3 years ago
parent
commit
473455635e

+ 1 - 1
src/sentry/search/events/builder.py

@@ -301,7 +301,7 @@ class TopEventsQueryBuilder(TimeseriesQueryBuilder):
                 project_condition = [
                     condition
                     for condition in self.where
-                    if condition.lhs == self.column("project_id")
+                    if type(condition) == Condition and condition.lhs == self.column("project_id")
                 ][0]
                 self.where.remove(project_condition)
                 if field == "project":

+ 19 - 0
tests/snuba/api/endpoints/test_organization_events_stats.py

@@ -2147,5 +2147,24 @@ class OrganizationEventsStatsTopNEventsWithSnql(OrganizationEventsStatsTopNEvent
             in mock_query.mock_calls[1].args[0].where
         )
 
+    def test_top_events_boolean_condition_and_project_field(self):
+        with self.feature(self.enabled_features):
+            response = self.client.get(
+                self.url,
+                data={
+                    "start": iso_format(self.day_ago),
+                    "end": iso_format(self.day_ago + timedelta(hours=2)),
+                    "interval": "1h",
+                    "yAxis": "count()",
+                    "orderby": ["-count()"],
+                    "field": ["project", "count()"],
+                    "topEvents": 5,
+                    "query": "event.type:transaction (transaction:*a OR transaction:b*)",
+                },
+                format="json",
+            )
+
+        assert response.status_code == 200
+
     def test_top_events_with_to_other(self):
         super().test_top_events_with_to_other()