aasm / aasm/aasm

failures colliding across objects

Open
#437 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
5.2k
Forks
644
PR merge metrics
No merged PRs in 30d

Description

I am using this with active record and thus have many objects in a variety of states. I found tests failing intermittently and narrowed down what is going on to a failing example.
I create two different objects and ask them to complete a failed transition. The second picks up the failures of the first...
I've seen long chains of failures added to the one I expected. I assume there were multiple previous transition failures that got tacked on to the object where I was validating the error.

Here is the test code I am using to show the issue using minitest:

  def test_leaks
    library = Fabricate(:library, name: 'lib')
    another_library = Fabricate(:library, name: 'another_lib')
    error = assert_raise(AASM::InvalidTransition) do
      library.submit!
    end
    assert_equal "Event 'submit' cannot transition from 'development'. Failed callback(s): [:last_build_succeeded?].", error.message
    error = assert_raise(AASM::InvalidTransition) do
      binding.pry # just using this to step down into the guts
      another_library.submit!
    end
    assert_equal "Event 'submit' cannot transition from 'development'. Failed callback(s): [:last_build_succeeded?].", error.message
  end

For the second failure message I get:
"Event 'submit' cannot transition from 'development'. Failed callback(s) [:last_build_succeeded?, :last_build_succeeded?]"

inside of aasm(4.11.1)/core/event.rb:#95 i see that transitions.flatmap &:failures is [:last_build_succeeded?, :last_build_succeeded?]

I'll dive in more tomorrow. I'll also provide the dsl from my model.
seems related to https://github.com/aasm/aasm/issues/401

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction in the issue and inspect aasm(4.11.1)/core/event.rb around line 95, where transitions.flatmap(&:failures) is reported to contain duplicate failures. Compare the behavior of two separate Active Record objects and review related issue #401. Done means the second object's InvalidTransition message contains only its own failed callbacks, with a regression test covering the case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.