Skip to content

fix(dashboards): Prevent IndexError for deleted dashboard creators - #122945

Merged
skaasten merged 3 commits into
masterfrom
seer/fix/dashboard-serializer-deleted-user
Aug 28, 2026
Merged

fix(dashboards): Prevent IndexError for deleted dashboard creators#122945
skaasten merged 3 commits into
masterfrom
seer/fix/dashboard-serializer-deleted-user

Conversation

@sentry

@sentry sentry Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

This PR addresses an IndexError: list index out of range that occurred when fetching dashboard details if the user who created the dashboard had been deleted.

Root Cause:
The DashboardDetailsModelSerializer unconditionally accessed [0] on the result of user_service.serialize_many when populating the createdBy field. If obj.created_by_id was set but the corresponding user no longer existed, user_service.serialize_many would return an empty list, leading to an IndexError.

Solution:

  1. Refactor get_attrs: The logic to fetch dashboard creators has been moved from serialize to get_attrs. This allows for bulk fetching of all creator users for a list of dashboards in a single user_service.serialize_many call, eliminating N+1 RPC queries.
  2. Safe Access in serialize: The createdBy field now safely retrieves the serialized user from the attrs dictionary. If the user is not found (e.g., because they were deleted), None is returned for createdBy instead of raising an IndexError.

Test Plan:
Added a unit test test_get_created_by_is_none_when_creator_deleted to OrganizationDashboardDetailsGetTest which mocks user_service.serialize_many to return an empty list and asserts that createdBy is None in the response.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Fixes SENTRY-5TSM

Comment @sentry <feedback> on this PR to have Autofix iterate on the changes.

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 27, 2026
@sentry sentry Bot changed the title fix(serializers): Handle deleted users in DashboardDetailsModelSerializer fix(dashboards): Handle deleted created_by users and optimize serialization Aug 27, 2026
@sentry sentry Bot changed the title fix(dashboards): Handle deleted created_by users and optimize serialization fix(dashboards): Prevent IndexError for deleted dashboard creators Aug 28, 2026
@skaasten
skaasten marked this pull request as ready for review August 28, 2026 14:21
@skaasten
skaasten requested a review from a team as a code owner August 28, 2026 14:21
@skaasten skaasten added the Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests label Aug 28, 2026
@skaasten
skaasten enabled auto-merge (squash) August 28, 2026 14:55
@skaasten
skaasten merged commit b433ee1 into master Aug 28, 2026
93 of 97 checks passed
@skaasten
skaasten deleted the seer/fix/dashboard-serializer-deleted-user branch August 28, 2026 15:21
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 Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants