Browse Source

fix(seach): Ensure an `aggregated_def` is not a user-created tag (#12530)

* Added a check if an aggregated_def is a tag to not add to having but instead add it to conditions.

* removed linter changes  from event search.

* fixed test that checkd if priority ordering still worked.

* Added  a  bunch of group1 events to give a higher priority score than group 2

* Only create 2 evevents to make the test faster
Lauryn Brown 6 years ago
parent
commit
ca85daad3f
2 changed files with 71 additions and 1 deletions
  1. 3 1
      src/sentry/search/snuba/backend.py
  2. 68 0
      tests/snuba/search/test_backend.py

+ 3 - 1
src/sentry/search/snuba/backend.py

@@ -415,7 +415,9 @@ def snuba_search(start, end, project_ids, environment_ids, sort_field,
         ):
             continue
         converted_filter = convert_search_filter_to_snuba_query(search_filter)
-        if search_filter.key.name in aggregation_defs:
+
+        # Ensure that no user-generated tags that clashes with aggregation_defs is added to having
+        if search_filter.key.name in aggregation_defs and not search_filter.key.is_tag:
             having.append(converted_filter)
         else:
             conditions.append(converted_filter)

+ 68 - 0
tests/snuba/search/test_backend.py

@@ -472,6 +472,74 @@ class SnubaSearchTest(SnubaTestCase):
         )
         assert set(results) == set([])
 
+    def test_search_filter_query_with_custom_priority_tag(self):
+        priority = 'high'
+        self.store_event(
+            data={
+                'fingerprint': ['put-me-in-group2'],
+                'timestamp': (self.group2.first_seen + timedelta(days=1)).isoformat()[:19],
+                'stacktrace': {
+                    'frames': [{
+                        'module': 'group2'
+                    }]
+                },
+                'message': 'group2',
+                'tags': {
+                    'priority': priority,
+                },
+            },
+            project_id=self.project.id,
+        )
+
+        results = self.make_query(
+            search_filter_query='priority:%s' % priority,
+            tags={'priority': priority},
+        )
+
+        assert set(results) == set([self.group2])
+
+    def test_search_filter_query_with_custom_priority_tag_and_priority_sort(self):
+        priority = 'high'
+        for i in range(1, 3):
+            self.store_event(
+                data={
+                    'fingerprint': ['put-me-in-group1'],
+                    'timestamp': (self.group2.last_seen + timedelta(days=i)).isoformat()[:19],
+                    'stacktrace': {
+                        'frames': [{
+                            'module': 'group1'
+                        }]
+                    },
+                    'message': 'group1',
+                    'tags': {
+                        'priority': priority,
+                    },
+                },
+                project_id=self.project.id,
+            )
+        self.store_event(
+            data={
+                'fingerprint': ['put-me-in-group2'],
+                'timestamp': (self.group2.last_seen + timedelta(days=2)).isoformat()[:19],
+                'stacktrace': {
+                    'frames': [{
+                        'module': 'group2'
+                    }]
+                },
+                'message': 'group2',
+                'tags': {
+                    'priority': priority,
+                },
+            },
+            project_id=self.project.id,
+        )
+        results = self.make_query(
+            search_filter_query='priority:%s' % priority,
+            tags={'priority': priority},
+            sort_by='priority',
+        )
+        assert list(results) == [self.group1, self.group2]
+
     def test_project(self):
         results = self.make_query([self.create_project(name='other')])
         assert set(results) == set([])