dry-rb / dry-transaction

Business transaction DSL
http://dry-rb.org/gems/dry-transaction
MIT License
468 stars 55 forks source link

Nested transactions with step arguments fail with ArgumentError #125

Open wintersolutions opened 5 years ago

wintersolutions commented 5 years ago

When calling a transaction from another transaction the call fails if step_args are provided.

Error message:

ArgumentError:
       wrong number of arguments (given 2, expected 0..1)
     # ./lib/dry/transaction/instance_methods.rb:25:in `call'

pseudocode:

nested = Class.new do
 include Dry::Transaction
 step :process
 def process(input, *args); Success; end
end.new

# register nested in container C

root = Class.new do
  include Dry::Transaction(container: C)
  step :root, with: nested
end.new

root.call # ok
root.with_step_args(root: 'foo').call # error

The issue seems to be that the arguments can't be passed down to the nested transaction but the lib tries to.

I've prepared a test case that demonstrates this in the pull request. It does not provide any solution to the issue yet.

Short discussion on discourse:

https://discourse.dry-rb.org/t/nested-transactions-with-step-arguments-buggy/757

wintersolutions commented 5 years ago

See issue #124