edisonywh / gearbox

⚙️ Gearbox is a functional state machine with an easy-to-use API, inspired by both Fsm and Machinery
MIT License
180 stars 10 forks source link

fix: maybe_apply_changeset_changes in Gearbox.Ecto overriding the original struct changes in transition_changeset #13

Closed suzdalnitski closed 2 years ago

suzdalnitski commented 2 years ago

This PR fixes an issue that I've inadvertently introduced in my previous PR: https://github.com/edisonywh/gearbox/pull/12

The culprit was this line, which overrode any previous changeset changes by applying them:

struct = maybe_apply_changeset_changes(struct)

This is a problem whenever using this function with Ecto - this will leave the changes empty, and any previous changes made before Gearbox.Ecto will not get applied by Ecto when running Repo.update.

The fix is to only use the struct with applied changes within the validate_transition function only.

suzdalnitski commented 2 years ago

By the way, you should be able to get the Travis CI status check unstuck by removing the "required status checks" on the master branch, and then adding them back in again:

https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks

edisonywh commented 2 years ago

Ah great catch, this was the same issue in #6. I've added a test and will merge it, thanks for the contribution!

edisonywh commented 2 years ago

Tagged and release as 0.3.3, thanks!

suzdalnitski commented 2 years ago

Thank you!