gocardless / statesman

A statesmanlike state machine library.
https://gocardless.com/blog/statesman/
MIT License
1.78k stars 163 forks source link

undefined method `transition_class' for #<Class:...> #368

Closed NGMarmaduke closed 5 years ago

NGMarmaduke commented 5 years ago

When bumping to version v4.1.3 we get the following error:

Failure/Error: include Statesman::Adapters::ActiveRecordQueries

NoMethodError:
  undefined method `transition_class' for #<Class:0x0000561a2f2b6548>
  Did you mean?  transaction
# ./vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
# ./vendor/bundle/ruby/2.6.0/gems/statesman-4.1.3/lib/statesman/adapters/active_record_queries.rb:22:in `included'
# ./app/models/share_profile.rb:2:in `include'
# ./app/models/share_profile.rb:2:in `<class:ShareProfile>'
# ./app/models/share_profile.rb:1:in `<top (required)>'

We have defined the class method transition_class as:

def self.transition_class
  ShareProfileTransition
end
private_class_method :transition_class

def self.initial_state
  ShareProfileStateMachine.initial_state
end

Using the new [] syntax on the module import fixes the issue, but as a patch release I assume this error was not intended to be introduced at this time.

NGMarmaduke commented 5 years ago

FYI the 4.1.3 release has a 44% compatibility: https://dependabot.com/compatibility-score/?dependency-name=statesman&package-manager=bundler&previous-version=4.1.2&new-version=4.1.3

danwakefield commented 5 years ago

Thanks for letting us know. We are debating releasing a new minor release without the breaking change vs yanking the broken one and will decide this today.

See https://github.com/gocardless/statesman/pull/370

danwakefield commented 5 years ago

This has now been fixed as much as a broken release can be.

4.1.4 has the same interface as 4.1.2 and earlier.

If people have changed their code to use new mixin style e.g

  include Statesman::Adapters::ActiveRecordQueries[
    transition_class: OrderTransition,
    initial_state: OrderStateMachine.initial_state
  ]

They should now use v5.0.0 which has this in its correct form.

If people changed their code so that the definitions of the class methods are before the include e.g from

  include Statesman::Adapter::ActiveRecordQueries

  def self.transition_class
    OrderTransition
  end

to

  def self.transition_class
    OrderTransition
  end

  include Statesman::Adapter::ActiveRecordQueries

Both v4.1.4 and v5.0.0 will work correctly.

We apologize for the inconvenience that this has caused.