Skip to content

fix(api): Prevent KeyError when partially updating project rules#115242

Draft
sentry[bot] wants to merge 1 commit intomasterfrom
seer/fix/api-project-rule-keyerror
Draft

fix(api): Prevent KeyError when partially updating project rules#115242
sentry[bot] wants to merge 1 commit intomasterfrom
seer/fix/api-project-rule-keyerror

Conversation

@sentry
Copy link
Copy Markdown
Contributor

@sentry sentry Bot commented May 8, 2026

This PR addresses a KeyError: 'name' that occurred when performing a partial PUT update on a project rule via the /api/0/projects/{organization_id_or_slug}/{project_id_or_slug}/rules/{rule_id}/ endpoint.

The DrfRuleSerializer is configured with partial=True, which correctly allows clients to omit fields like name or actionMatch when updating a rule. However, the endpoint's put method was directly accessing data["name"] and data["actionMatch"] from the serializer.validated_data dictionary. If these fields were not present in the partial request body, a KeyError would be raised.

The fix involves replacing these direct dictionary accesses with .get() calls, providing a fallback to the existing rule's values (rule.label for name, rule.data.get("action_match") for actionMatch, and rule.data.get("actions", []) for actions). This ensures that omitted fields in a partial update gracefully retain their current values, aligning the behavior with the partial=True serializer configuration.

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-5JP3

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 8, 2026
@mrduncan mrduncan added the Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests label May 8, 2026
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.

1 participant