Closed ericgross closed 4 years ago
Statesman should be raising TransitionConflictError
in this case. See below.
Can you tell me the Database and version you are using and I'll try to figure out if transition_conflict_error?
should be changed in some way.
My immediate thought is that the error you are receiving is from ActiveRecord model validations (See the default error message here https://guides.rubyonrails.org/active_record_validations.html#uniqueness)
Statesman only retry's when the error has come from the database from a constraint. You could remove the validation and rely on the constraint to fix things.
You could also monkey-patch the create
method above to catch ActiveRecord::RecordInvalid
and turn it into a TransitionConflictError
Frequently I'll get this error in statesman 3.5.0 from my background jobs:
Validation failed: Sort key has already been taken
from this line of code:
Statesman::Machine.retry_conflicts(1) { order.transition_to!(:recipe_customized) }
I see that
retry_conflicts
only rescues fromTransitionConflictError
exceptions - but I think it should also rescue from (and retry) the error I am seeing - is that right?