Skip to content

fix(workflow): Eliminate N+1 queries in workflow serializers - #124245

Draft
sentry[bot] wants to merge 2 commits into
masterfrom
seer/fix/workflow-serializer-n-plus-1
Draft

fix(workflow): Eliminate N+1 queries in workflow serializers#124245
sentry[bot] wants to merge 2 commits into
masterfrom
seer/fix/workflow-serializer-n-plus-1

Conversation

@sentry

@sentry sentry Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

This PR addresses an N+1 query issue identified in the WorkflowSerializer and DataConditionGroupSerializer when fetching related objects.

Specifically:

  • In WorkflowSerializer.get_attrs, WorkflowDataConditionGroup objects were being iterated over, causing an N+1 query for each condition_group access. This is fixed by adding .select_related("condition_group") to the queryset.
  • In DataConditionGroupSerializer.get_attrs, DataConditionGroupAction objects were similarly causing an N+1 query for each action access. This is fixed by adding .select_related("action") to the queryset.

Regression tests have been added to both test_workflow_serializer.py and test_data_condition_group_serializer.py to ensure that bulk serialization no longer results in an increasing number of database queries.

CI failures related to mypy (missing return type annotations for helper functions) and ruff-format (line length/formatting) in the new test code have also been resolved.

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

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

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 Sep 12, 2026
@sentry sentry Bot changed the title fix(serializers): Resolve N+1 queries in workflow and data condition group serializers fix(workflow): Eliminate N+1 queries in workflow serializers Sep 12, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants