Closed deemytch closed 4 years ago
You are right: to use the latest workflow
gem in version 2 or later, all persistence libraries, e.g. workflow-sequel
need to be updated.
workflow-sequel
(they have instructions on Contributing)
or implement your own persistence as described in
https://github.com/geekq/workflow#custom-workflow-state-persistenceworkflow
. It is still available in github and via rubygems. Please read https://github.com/geekq/workflow#state-persistence-with-activerecordВладимир, but the bug that I opened is about that persistence with sequel, exactly as described in docs does not works. And I can't get why.
UniqueViolation... Ключ "(id)=(2)" уже существует
looks like a record with the same id already exists. Does error happens directly on Sequelbag.create
? Is it supposed to save the record immediately? persist_workflow_state
should not cause this since it is not called for new records but only in process_event!
https://github.com/geekq/workflow/blob/develop/lib/workflow.rb#L97-L125
Can you please provide a complete minimal application (if it is a Rails-Application) or even a self-contained single-file script demonstrating the problem + Gemfile so I can easily reproduce?
Yes, and this appears when updating exisiting record and only when the class contains include Workflow
. I will make the script soon.
https://github.com/deemytch/workflow-sequel-bag Edit createdb.sql and sequelbag.rb if you need to change user/password/database. Run main.sh there.
:+1: was able to reproduce.
Now try to change state name from :new
to something else like :neww
and see what happens!
Background: if you define some workflow states and events, a bunch of convinience methods are created behind the scene. Looks like one of them collides with the methods used by the Sequel::Model implementation - likely new?
How I debugged:
persist_workflow_state
, before_validation
etc. Problem was still there.include Workflow
- still worksworkflow do
block - still works:new
state had a problemI should probably mention it in the documentation.
Где были мои глаза? Володя, спасибо!
Throws
Sequel::UniqueConstraintViolation: PG::UniqueViolation
when updating the model. Working ok without including Workflow into model. gem workflow-sequel is not working too, it is outdated, and that code is copied from it.ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux] postgresql 11.4 workflow 2.0.2 sequel 5.22.0
Below is the example test code.
Here you need to connect to database.
Then you define the model class.
If the class does not
include Workflow
and so on all updates on my models are working fine. And that's all, floks.