Comments (14)
Can validate that this is happening on my application:
Rails 6.0.6.1
Ruby 3.0.6 (formerly 2.7.7)
AASM 5.5.0
request.accept! # => ArgumentError: wrong number of arguments (given 1, expected 0)
request.accept # => succeeds
from aasm.
I'm guessing the problem is somewhere between
124: safely_define_method klass, "#{name}!", ->(*args, &block) do
125: aasm(aasm_name).current_event = :"#{name}!"
126: aasm_fire_event(aasm_name, event, {:persist => true}, *args, &block)
127: end
and
121: # Returns true if event was fired successfully and transaction completed.
122: def aasm_fire_event(state_machine_name, name, options, *args, &block)
123: return super unless aasm_supports_transactions? && options[:persist]
This is made complicated by the changes in args around ruby 3. In the lower code (ruby 3.2 in my case), args is an array with one hash in it. That's probably not what's wanted. Getting that to work for ruby 2.x and 3.x may involve something like
args_hash = Array(args).first
from aasm.
I found that location by stepping into my code where it was failing. I certainly didn't dig into the AASM code to figure out the right fix. It seems likely that my research could be useful for writing a failing test if nothing else. This issue will block my company from doing a ruby upgrade - which is not a priority for us this quarter. It will become a priority in a couple of months. I'm kind of hoping that it'll be fixed and pushed by then :-)
from aasm.
@kwerle we're in the same situation, and we might be taking a stab at it soon.
from aasm.
Ah - instead it is being passes as a hash: {:some_variable =>1234}
from aasm.
For those following with interest - I think I've given enough detail to formulate a reasonable test in #834 (comment) . I will not be pursuing this further - our workaround is to simply accept the hash and use that.
from aasm.
Ah - it looks like maybe this is fixed in https://github.com/aasm/aasm/tree/add_ruby_3.2_in_github_workflows
Looks like that was only a partial fix.
from aasm.
@kwerle is there a PR for that? I feel the proposed solution is a bit hacky, and also resolves the problem where it blows, not where it originates. The better solution would be to separate the keyword arguments in the Invoker
, and add Ruby 3.2 support there.
from aasm.
@kwerle the fix you mentioned is present on 5.5.0. Also, aasm is currently running with ruby 3.0 and rails 6.1 (not 6.0 yet). This example seems to implement the situations that both you and @that-jill discussed, and it seems to pass under all conditions. Can you create a failing spec?
from aasm.
Can you create a failing spec?
I'm on an M1 mac and do all my dev work in docker containers. I have not been able to get the aasm test environment up and running so I don't believe I will be able to write a good test. If nobody else tackles this before we really need it, I'll provide a monkey patch that addresses the issue - probably later this quarter.
from aasm.
I forgot to link the example I believe represents your problem now, and is passing on main.
aasm/spec/unit/event_multiple_spec.rb
Line 21 in ed88361
Do you agree that it's the same case? If you don't, we could work together to get a failing spec and I can take care of fixing it.
from aasm.
I'm starting to dig into this, and the first broken spot I see is we have:
event :submit do
before { |some_variable:| self.foo = some_variable }
transitions from: ...
success :...
end
my_object.submit(some_variable: 1234)
It looks like in ruby 3.2 and aasm 5.5.0 before
is no longer being called with the some_variable: hash parameter.
from aasm.
We have the same problem here. Has anyone found a way to fix it?
from aasm.
@fbraure the current workaround is to simply accept the argument as a hash and fetch options from it, as pointed by @kwerle
from aasm.
Related Issues (20)
- Timestamps column name with enum and _prefix HOT 1
- Active Record upgrade 5 to 6 : AASM does not clear the activerecord cache after calling an event HOT 2
- I have a question
- AASM and graphql
- Tag releases v5.3.1, v5.4.0 and v5.5.0 HOT 1
- Invalid error is not using locale setup in the application
- Custom auto-save feature
- Namespaced scopes perform incorrect queries HOT 2
- raising in aasm_fire_event does not rollback transaction HOT 1
- Multiple state machines per class don't work properly with automatic scopes HOT 1
- Multiple state machines per class don't work properly with automatic state constants HOT 2
- Can't pass an empty hash as callback parameters to `transition_from` since 5.5.0 HOT 2
- callbacks endless loop HOT 2
- Update RSpec helper to reset states with `binding_event`
- Stopping event without raising from after callback HOT 1
- gem misses CHANGELOG HOT 1
- Performance of aasm_ensure_initial_state (end Rails 3 support?) HOT 1
- Callback with positional and keyword args errors out in Ruby 3.2
- Revisit "Add :after_commit callbacks to events"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aasm.