Skip to content

fix(ACI): Parse and persist owner field#110807

Merged
ceorourke merged 8 commits intomasterfrom
ceorourke/ISWF-2237
Mar 18, 2026
Merged

fix(ACI): Parse and persist owner field#110807
ceorourke merged 8 commits intomasterfrom
ceorourke/ISWF-2237

Conversation

@ceorourke
Copy link
Copy Markdown
Member

Follow up to #110785 and #110381 to write and update the owner on a workflow if that data is passed to the legacy endpoint and we have the feature flag flipped so that we single write.

@ceorourke ceorourke requested a review from a team as a code owner March 16, 2026 21:48
@linear-code
Copy link
Copy Markdown

linear-code bot commented Mar 16, 2026

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on d0e5fbb in this run:

tests/sentry/api/endpoints/test_project_rule_details.py::UpdateProjectRuleTest::test_update_owner_typelog
tests/sentry/api/endpoints/test_project_rule_details.py:752: in test_update_owner_type
    workflow = Workflow.objects.get(id=workflow_response.data["id"])
.venv/lib/python3.13/site-packages/django/db/models/manager.py:87: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
.venv/lib/python3.13/site-packages/django/db/models/query.py:635: in get
    raise self.model.DoesNotExist(
E   sentry.workflow_engine.models.workflow.Workflow.DoesNotExist: Workflow matching query does not exist.

Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

if actor is not None:
workflow_payload["owner"] = actor.identifier
elif owner is None: # user has expliticly passed None so as to clear the owner field
workflow_payload["owner"] = None
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.

Redundant owner validation causes duplicate DB queries

Low Severity

The parse_and_validate_actor call in format_request_data validates the owner (resolving the actor and checking org membership via DB queries), then stores actor.identifier (e.g., "user:123"). The WorkflowValidator's OwnerActorField then calls parse_and_validate_actor again on the same value, repeating the same DB queries. The OwnerActorField can handle all raw owner formats (int, string, None) directly, so the pre-processing in format_request_data is unnecessary. Additionally, a validation error raised here produces a flat error response, while one from the WorkflowValidator would be keyed under the owner field — an inconsistency.

Fix in Cursor Fix in Web

@ceorourke ceorourke requested a review from saponifi3d March 17, 2026 20:48
Comment on lines +759 to +762
owner = data.get("owner", "")
if owner:
actor = parse_and_validate_actor(str(owner), project.organization_id)
if actor is not None:
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.

Bug: The WorkflowValidator is missing the current_owner context, causing incorrect validation failures when a user reassigns rule ownership from their own team to another team.
Severity: MEDIUM

Suggested Fix

When instantiating the WorkflowValidator in the project_rule_details.py PUT endpoint, add the current_owner to the context dictionary, similar to how it is provided to the DrfRuleSerializer in the non-feature-flagged code path.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry/api/endpoints/project_rules.py#L759-L762

Potential issue: When updating a rule via the PUT endpoint with the
`organizations:workflow-engine-rule-serializers` feature flag enabled, the
`WorkflowValidator` is instantiated without the `current_owner` in its context. This
prevents the `OwnerActorField` from correctly validating team reassignments.
Specifically, it blocks a user from reassigning ownership from a team they are a member
of to a team they are not, as the logic to check the `current_owner` is skipped. This
results in an incorrect validation failure for a legitimate user action.

@ceorourke ceorourke merged commit da45618 into master Mar 18, 2026
65 checks passed
@ceorourke ceorourke deleted the ceorourke/ISWF-2237 branch March 18, 2026 16:42
ceorourke added a commit that referenced this pull request Mar 20, 2026
Follow up to
#109926 (comment)
to increase test coverage for the issue alert rule POST endpoint
backwards compatibility. Adding this test coverage uncovered a few
inconsistencies that are fixed in this PR as well.

Note that I will need to rebase off of
#110807 once it is merged.
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.

2 participants