Skip to content

fix(teams): Deduplicate project features list#112326

Merged
scttcper merged 7 commits intomasterfrom
scttcper/fix-team-project-features-dupe
Apr 7, 2026
Merged

fix(teams): Deduplicate project features list#112326
scttcper merged 7 commits intomasterfrom
scttcper/fix-team-project-features-dupe

Conversation

@scttcper
Copy link
Copy Markdown
Member

@scttcper scttcper commented Apr 7, 2026

When a project belongs to multiple teams, the team serializer was building the projects list from the ProjectTeam join table without deduplicating. This meant get_features_for_projects() iterated the same project N times (once per team it belongs to), appending features to the same list each time. The features array in the response ended up with N copies of every feature.

Deduplicates the project list before passing it to serialize().

You can see duplicates in the production endpoint https://us.sentry.io/api/0/organizations/sentry/teams/

When a project belongs to multiple teams, the team serializer was
passing duplicate Project objects into serialize(). This caused
get_features_for_projects() to append features once per duplicate,
so the features array multiplied by the number of teams a project
was on.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 7, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@scttcper scttcper requested a review from a team April 7, 2026 17:06
@scttcper scttcper marked this pull request as ready for review April 7, 2026 17:06
@scttcper scttcper requested a review from a team as a code owner April 7, 2026 17:06
@scttcper scttcper changed the title fix(api): Deduplicate projects before serializing in team response fix(teams): Deduplicate projects before serializing in team response Apr 7, 2026
@scttcper scttcper changed the title fix(teams): Deduplicate projects before serializing in team response fix(teams): Deduplicate project features list Apr 7, 2026
projects = [pt.project for pt in project_teams]

# A project can be on multiple teams, dedupe before serializing
projects = list({pt.project_id: pt.project for pt in project_teams}.values())
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.

it seems like this is the only user of get_for_teams_with_org_cache, we could in theory dedupe on the query level.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(letting the clanker respond)

We still need the full join table for the project_map loop below (line 265-267) which maps each team to its projects. If we deduped at the query level we'd lose that team-to-project mapping. Could split it into two queries but that seems worse.

# A project can be on multiple teams, dedupe before serializing
projects = list({pt.project_id: pt.project for pt in project_teams}.values())

projects_by_id = {
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.

we could also do this deduping after projects_by_id to make it a little cleaner

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(letting the clanker respond)

The dedup has to happen before serialize() — that's where get_features_for_projects() iterates the list and appends to a defaultdict(list) keyed by project. If duplicates are in the input, features get appended N times to the same list before projects_by_id ever gets built.

@scttcper scttcper merged commit 96da026 into master Apr 7, 2026
60 checks passed
@scttcper scttcper deleted the scttcper/fix-team-project-features-dupe branch April 7, 2026 20:43
george-sentry pushed a commit that referenced this pull request Apr 9, 2026
When a project belongs to multiple teams, the team serializer was
building the projects list from the ProjectTeam join table without
deduplicating. This meant `get_features_for_projects()` iterated the
same project N times (once per team it belongs to), appending features
to the same list each time. The features array in the response ended up
with N copies of every feature.

Deduplicates the project list before passing it to `serialize()`.

You can see duplicates in the production endpoint
https://us.sentry.io/api/0/organizations/sentry/teams/

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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