Skip to content

fix save_with_state_error - #7

Merged
chaadow merged 1 commit into
chaadow:mainfrom
mathieu-valery:fix_save_with_state_feat
Jan 21, 2026
Merged

fix save_with_state_error#7
chaadow merged 1 commit into
chaadow:mainfrom
mathieu-valery:fix_save_with_state_feat

Conversation

@mathieu-valery

@mathieu-valery mathieu-valery commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

Hi Ched,

The purpose of this PR is to fix save_with_state since it returns true when a transition is invalid
In my use case if an operator tries to transition payment procedure from canceled to to_process), it silently fails since no @registered_callbacks gets registered then no transition is operated which I think is misleading the operator.

we can add an error if the transition is not possible but further fixes are needed :

  1. need to define private reader method def #{field_name} because it is needed by active record full_messages method
  2. Important. : this line if #{virtual_attribute_name}_changed? didnt work as expected. It always return true because Rails sees this as a change from nil → 'canceled', even though the effective value is the same. We need {virtual_attribute_name}.to_s != #{field_name}_current_state.to_s to check that state didnt change. In Sidecare some forms submit the current_state_value (payment procedure for instance) and without this proper check, these forms will always fail to update the instances

Hope you like it

@chaadow
chaadow force-pushed the fix_save_with_state_feat branch from e295954 to f962bf8 Compare January 21, 2026 00:02
@chaadow
chaadow merged commit 249a702 into chaadow:main Jan 21, 2026
2 checks passed
@chaadow

chaadow commented Jan 21, 2026

Copy link
Copy Markdown
Owner

Thanks a lot! I'll cut a release

@chaadow

chaadow commented Jan 21, 2026

Copy link
Copy Markdown
Owner

@mathieu-valery Released in v0.2.7

chaadow added a commit that referenced this pull request Feb 5, 2026
chaadow added a commit that referenced this pull request Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants