Skip to content

fix(issues): Match no issues for my_teams when the caller has no teams - #129424

Draft
gricha wants to merge 1 commit into
masterfrom
fix/my-teams-empty-matches-all
Draft

gricha wants to merge 1 commit into
masterfrom
fix/my-teams-empty-matches-all

Conversation

@gricha

@gricha gricha commented Oct 31, 2026

Copy link
Copy Markdown
Member

assigned:my_teams and assigned_or_suggested:my_teams matched every issue when the caller belongs to no teams.

my_teams resolves to the caller's teams. With none, the list is empty: assigned_to_filter([]) and assigned_or_suggested_filter([]) returned an empty Q(), which filters nothing. The inbox sort had the same gap: if owner_search: skipped the owner filter on an empty list.

Both filters now return Q(pk__in=[]) for an empty list, so the search matches nothing. !assigned:my_teams still matches everything, since excluding nothing keeps every row. Lists with at least one actor build the same query as before.

Who hit this: members with no teams, and API key / org token callers. They have no user, so get_teams_for_users returns no teams.

Found while narrowing request.user for service accounts, which have no teams either.

Evidence: test_my_teams_without_teams_matches_nothing (search backend) and test_sort_by_inbox_my_teams_without_teams (inbox sort) fail on master:

E   assert [<Group ...>] == []
E     Left contains 2 more items, first extra item: <Group ...>
E   AssertionError: assert [{'id': '681'...}] == []
FAILED tests/snuba/search/test_backend.py::EventsSnubaSearchTest::test_my_teams_without_teams_matches_nothing
FAILED tests/sentry/issues/endpoints/test_organization_group_index.py::GroupListTest::test_sort_by_inbox_my_teams_without_teams
2 failed, 284 deselected

and pass with the fix:

2 passed, 284 deselected

An empty my_teams list made assigned_to_filter and assigned_or_suggested_filter
return an empty Q(), and the inbox sort skipped its owner filter, so the search
matched every issue. Return Q(pk__in=[]) for an empty list instead.
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 31, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant