Skip to content

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

Merged
gricha merged 1 commit into
masterfrom
fix/my-teams-empty-matches-all
Nov 2, 2026
Merged

gricha merged 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
@gricha
gricha marked this pull request as ready for review November 2, 2026 18:55
@gricha
gricha requested review from a team as code owners November 2, 2026 18:55
@gricha
gricha requested a review from skaasten November 2, 2026 18:55

@cvxluo cvxluo left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this seems fine. i think this is technically a breaking change in the API but it doesn't seem like there's any significant automated usage of my_teams afaict (yet)

@gricha
gricha merged commit 796248a into master Nov 2, 2026
76 checks passed
@gricha
gricha deleted the fix/my-teams-empty-matches-all branch November 2, 2026 19:55
gricha added a commit that referenced this pull request Nov 3, 2026
… has no teams

assignee:my_teams ORed nothing onto Q() for a caller on no teams, and
filter(Q()) matches every detector. Return Q(pk__in=[]) instead, as
#129424 did for issue search.
gricha added a commit that referenced this pull request Nov 3, 2026
Issue endpoints (hashes, similar issues, notes, issue views,
supergroups, release commits) read the caller through
`sentry.auth.principal`; personal issue-view writes use
`require_user()`.

- A service account can unmerge (was a 500: `ServiceAccountId` isn't
serializable) and gets 404 editing notes it doesn't own; posting a note
and saving issue views stay 403 `user-required` by design. Seer no
longer receives a service-account id as the user. New tests cover
unmerge and notes.
- Legacy API keys get 401 instead of a 500 on starred issue views.
- Users and agents see no change.

Left on #129402's mypy allowlist: issue search (`convert_query_values`,
`parse_query`, `validate_search_filter_permissions`). Passing no user
there makes `assigned:my_teams` resolve to an empty team list, and
`assigned_to_filter([])` matches every issue: an existing bug for users
with no teams and API keys, fixed in #129424. Also
`get_create_issue_config` in `group_integration_details.py`.
gricha added a commit that referenced this pull request Nov 3, 2026
…list (#129402)

mypy now types DRF `request.user` as `User | AnonymousUser |
ServiceAccountPrincipal`, except in files on
`tools/mypy_helpers/request_user_allowlist.txt`. Those keep today's
type, so mypy stays green, while every other file must narrow before it
reads user-only attributes.

- **Plugin:** an attribute hook on `rest_framework.request.Request.user`
returns the union outside the allowlist. `report_config_data` rechecks a
cached module when it joins or leaves the list; the list is re-read when
the file changes, so a running `dmypy` uses the current list for any
file it rechecks. dmypy doesn't recheck an unchanged file just because
it joined or left the list; touch the file or restart the daemon.
- **Sentry only:** files outside this repo keep today's type. getsentry
loads this plugin through a `tools -> ../sentry/tools` symlink, and
without this its typing job failed with 10 errors in 5 files.
`test_drf_request_user_keeps_its_type_outside_sentry` runs mypy the way
getsentry does.
- **`ServiceAccountPrincipal.id`** is hidden from mypy (`if not
TYPE_CHECKING`) but kept at runtime, so `ServiceAccountId` still guards
unconverted reads.
- **Allowlist:** 23 files, exactly the ones with errors once the PRs
below land (31 errors): member management (4), issue search (5, after
#129424), `features.batch_has` (3) and 11 one-offs. A test fails if the
list grows or names a deleted file, and another fails if the hook stops
applying.
- **AGENTS.md:** a two-line note that fixing a file means removing it
from the list.

No runtime change. It lands after the fixes: the PRs below narrow the
rest, and each later fix removes its files from the list.
gricha added a commit that referenced this pull request Nov 4, 2026
… has no teams (#129608)

`assignee:my_teams` on the detector list returned every detector when
the caller is on no teams.

`convert_assignee_values` ORs one `Q` per resolved actor onto an empty
`Q()`. `my_teams` resolves to no actors for a member with no teams, so
the result stays `Q()`, and `filter(Q())` matches every row. #129424
fixed the same thing for issue search; this does it for detectors.
Negation is unchanged: `exclude(Q(pk__in=[]))` still keeps every row.
The test checks `!assignee:my_teams` still returns all three detectors.

`test_query_by_assignee_my_teams_without_teams` fails without the fix,
returning all 3 detectors (one owned by a team the caller isn't on, two
unowned):

```
E   AssertionError: assert [{'id': '1', ...': None, ...}] == []
E     Left contains 3 more items, first extra item: {'id': '1', ..., 'name': 'Error Monitor', ...}
FAILED tests/sentry/workflow_engine/endpoints/test_organization_detector_index.py::OrganizationDetectorIndexGetTest::test_query_by_assignee_my_teams_without_teams
```

With it, the file passes: `102 passed, 7 subtests passed`. An empty
`values` list (not reachable from the endpoint) now matches nothing
instead of everything; its unit test is updated.
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.

3 participants