New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
breaking change in 5.5.0 with literal_invoker #809
Comments
I have similar problems. It happens only in Ruby 3.2.
results in: |
I'm not able to replicate the first issue. However, here it is a reduced test case for the second issue, affecting Ruby 3.2 only. I think they are separate issues because the second one also affects aasm 5.4.0 # frozen_string_literal: true
require 'bundler/inline'
begin
gemfile(true) do
source 'https://rubygems.org'
gem 'aasm', '5.4.0' # it also affects 5.5.0
gem 'activerecord'
gem 'pg'
end
require 'aasm'
require 'active_record'
require 'logger'
rescue Gem::LoadError => e
puts "\nMissing Dependency:\n#{e.backtrace.first} #{e.message}"
rescue LoadError => e
puts "\nError:\n#{e.backtrace.first} #{e.message}"
exit 1
end
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'bench')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :loans, force: true do |t|
t.string :status
t.timestamp :closed_at
end
end
class Loan < ActiveRecord::Base
include AASM
aasm(column: :status) do
state :activated, initial: true
state :closed
event :close do
before do |closed_at:|
self.closed_at = closed_at
end
transitions from: :activated, to: :closed
end
end
end
loan = Loan.create!
loan.close! closed_at: Time.current |
I've also gotten the second issue. The root of it is here. The argument spat is being used to forward argument but starting in Ruby 3 hash arguments are not automatically converted to keyword arguments. This means both the position splat and the keyword splat needs to be used. A quick hack I implemented is: module AASM
module Ruby3ProcCompat
def exec_proc(parameters_size)
kwargs = {}
has_keyword_args = subject.parameters.any? { |(type, _)| type.to_s.starts_with? "key" }
if has_keyword_args
kwargs = args.extract_options!
parameters_size -= 1 if !kwargs.empty? && parameters_size > 0
end
return record.instance_exec(&subject) if parameters_size.zero?
return record.instance_exec(*args, **kwargs, &subject) if parameters_size < 0
record.instance_exec(*args[0..(parameters_size - 1)], **kwargs, &subject)
end
end
end
AASM::Core::Invokers::ProcInvoker.prepend AASM::Ruby3ProcCompat It hasn't really gotten much testing so use with caution. A more complete solution probably needs more refactoring. A few things that to point out:
|
I actually wonder if the original posters issue relates to the fix in #808? Could one of their args be a hash even though the method only accepts position params and therefore it's being invoked incorrectly? |
Hi,
It looks like there is a breaking change in the latest version 5.5.0 with callbacks.
I call transitions by calling them with arguments like this_event!(arg1, arg2). This has worked perfectly up to the latest change.
Now I get:
The text was updated successfully, but these errors were encountered: