Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/sentry/utils/snuba.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def _preprocess_group_id_redirects(self):
out_groups: set[int | str] = set()
if "group_id" in self.filter_keys:
self.filter_keys = self.filter_keys.copy()
in_groups = get_all_merged_group_ids(self.filter_keys["group_id"])
in_groups = set(self.filter_keys["group_id"])
del self.filter_keys["group_id"]

new_conditions = []
Expand All @@ -953,12 +953,12 @@ def _preprocess_group_id_redirects(self):
op = triple[1]
# IN statements need to intersect
if op == "IN":
new_in_groups = get_all_merged_group_ids(triple[2])
new_in_groups = set(triple[2])
if in_groups is not None:
new_in_groups = in_groups.intersection(new_in_groups)
in_groups = new_in_groups
elif op == "=":
new_in_groups = get_all_merged_group_ids([triple[2]])
new_in_groups = {triple[2]}
if in_groups is not None:
new_in_groups = in_groups.intersection(new_in_groups)
in_groups = new_in_groups
Expand All @@ -968,13 +968,13 @@ def _preprocess_group_id_redirects(self):
elif op == "!=":
out_groups.add(triple[2])

out_groups = get_all_merged_group_ids(list(out_groups))
out_groups = get_all_merged_group_ids(out_groups)
triple = None
# If there is an "IN" statement, we don't need a "NOT IN" statement. We can
# just subtract the NOT IN groups from the IN groups.
if in_groups is not None:
in_groups.difference_update(out_groups)
triple = ["group_id", "IN", in_groups]
triple = ["group_id", "IN", get_all_merged_group_ids(in_groups)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expanded exclusions can be reintroduced after late expansion

The difference_update on line 976 removes expanded out_groups from raw in_groups, but then line 977 expands in_groups which can re-introduce group IDs that were in out_groups. For example, if group 1 redirects to 10 and group 100 also redirects to 10, a query group_id = 1 AND group_id != 100 would have out_groups = {100, 10} but in_groups = {1}. After difference_update, in_groups stays {1}, but after expansion becomes {1, 10}, incorrectly including 10 which the user tried to exclude.

Fix in Cursor Fix in Web

elif len(out_groups) > 0:
triple = ["group_id", "NOT IN", out_groups]

Expand Down
Loading