Open
Conversation
Test coverage89.73% line coverage reported by SimpleCov. |
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.
d913977 to
4e3fa83
Compare
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
4e3fa83 to
3fb1133
Compare
Contributor
There was a problem hiding this comment.
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::SetStatusto no-op when already in the target state, guard invalid transitions withcan_transition_to?, and retry onStatesman::TransitionConflictError. - Extends
SchoolProjectdelegation to includein_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.
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.
94eb8bf to
aa514e2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status
What's changed?
StandardError, and instead handle theStatesman::TransitionConflictErrorby retrying andStatesman::TransitionFailedErrorby avoiding those transitionsSee commits for more.