Skip to content

Stop transition failed errors#788

Open
zetter-rpf wants to merge 3 commits intomainfrom
stop-transition-failed-errors
Open

Stop transition failed errors#788
zetter-rpf wants to merge 3 commits intomainfrom
stop-transition-failed-errors

Conversation

@zetter-rpf
Copy link
Copy Markdown
Contributor

@zetter-rpf zetter-rpf commented Apr 22, 2026

Status

What's changed?

  • Don't raise errors when projects are already in the state being transitioned to
  • Don't StandardError, and instead handle the Statesman::TransitionConflictError by retrying and Statesman::TransitionFailedError by avoiding those transitions

See commits for more.

@cla-bot cla-bot Bot added the cla-signed label Apr 22, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

Test coverage

89.73% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/24781553158

This pattern masks errors in test and creates noise for expected errors
Replace it with a test for the expected error case that we want to
handle.
@zetter-rpf zetter-rpf force-pushed the stop-transition-failed-errors branch from d913977 to 4e3fa83 Compare April 22, 2026 12:49
Avoid transitioning the state if it's already in that state. Presumably this might happen if someone double-submits something in the frontend. There are currently errors in sentry for all the controller actions.

This is safe to do as we don't perform any actions in the SchoolProjectsController if this was successful (such as sending emails).

I've removed the specs around complete - since the complete to complete is guarded against and all other states can transition to complete, there are no invalid transitions to test.

Note this won't catch errors that might happen if the school project state has already been updated by process after it is loaded. If we see this happen in Sentry we can catch that specific error.

second
@zetter-rpf zetter-rpf force-pushed the stop-transition-failed-errors branch from 4e3fa83 to 3fb1133 Compare April 22, 2026 12:55
@zetter-rpf zetter-rpf marked this pull request as ready for review April 22, 2026 13:32
Copilot AI review requested due to automatic review settings April 22, 2026 13:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adjusts school project status transitions to avoid errors when transitioning to the current state and to reduce Statesman transition-related failures during concurrent updates (issue #1310).

Changes:

  • Updates SchoolProject::SetStatus to no-op when already in the target state, guard invalid transitions with can_transition_to?, and retry on Statesman::TransitionConflictError.
  • Extends SchoolProject delegation to include in_state? for the new no-op behavior.
  • Updates request/unit specs to reflect the new transition behavior and add retry-related coverage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
spec/features/school_project/complete_spec.rb Removes the prior “complete → complete” error expectation (behavior change).
spec/concepts/school_project/set_status_spec.rb Updates unit specs for invalid transitions, same-state no-op, and retry behavior.
lib/concepts/school_project/set_status.rb Implements retry-on-conflict, same-state no-op, and invalid-transition guarding.
app/models/school_project.rb Delegates in_state? to the state machine for the new logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/concepts/school_project/set_status.rb
Comment thread lib/concepts/school_project/set_status.rb Outdated
Comment thread spec/concepts/school_project/set_status_spec.rb Outdated
Comment thread spec/features/school_project/complete_spec.rb
When looking through sentry, the only other error from the school projects controller is a Statesman::TransitionConflictError. This might happen if the object has already transitioned between it being loaded and the request running.

Retry the request once to handle this.
@zetter-rpf zetter-rpf force-pushed the stop-transition-failed-errors branch from 94eb8bf to aa514e2 Compare April 22, 2026 13:39
Copy link
Copy Markdown
Contributor

@cocomarine cocomarine left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants