# Dry-transaction invalid result from around step adapter

**URL:** <https://discourse.dry-rb.org/t/dry-transaction-invalid-result-from-around-step-adapter/589>\
**Category:** Support\
**Created:** [July 20, 2018, 12:58pm UTC](https://discourse.dry-rb.org/t/dry-transaction-invalid-result-from-around-step-adapter/589 "2018-07-20T12:58:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SheepD](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@SheepD](https://discourse.dry-rb.org/u/SheepD)\
**Post date:** [July 20, 2018, 12:58pm UTC](https://discourse.dry-rb.org/t/dry-transaction-invalid-result-from-around-step-adapter/589/1 "2018-07-20T12:58:14Z")

</div>

So I am following [http://dry-rb.org/gems/dry-transaction/around-steps/](http://dry-rb.org/gems/dry-transaction/around-steps/) and i have decided to try out transactions in my app

my transaction looks something like this

```ruby
class MyTransaction
  include Dry::Transaction(container: MyContainer)

  around :transaction, wtih: 'transaction'
  step :create_one
  step :create_two
end

```

and my around transaction looks like this from my container

```ruby
  register('transaction') do |input, &block|
    result = nil

    begin
      ActiveRecord::Base.transaction do
        binding.pry
        result = block.call(Success.new(input))
        binding.pry
        raise ActiveRecord::Rollback if result.failure?
        result
      end
    rescue ActiveRecord::Rollback
      # the code never reached here...
      result
    end
  end

```

it works fine when there are no failures, but when a failure occurs… I get this error `Dry::Transaction::InvalidResultError (step +transaction+ must return a Result object)` from the around transaction… i tried debugging to see what seems to be the cause but control doesn’t seem to enter the rescue block

did i do something wrong with my around step?

---

<div class="post-metadata">

**Author:** ![SheepD](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@SheepD](https://discourse.dry-rb.org/u/SheepD)\
**Post date:** [July 20, 2018, 1:18pm UTC](https://discourse.dry-rb.org/t/dry-transaction-invalid-result-from-around-step-adapter/589/2 "2018-07-20T13:18:28Z")

</div>

Turns out it was an error with my usage of ActiveRecord::Rollback rather than an issue with dry-transaction

I would like to request to have this thread closed. thanks!

---

<div class="post-metadata">

**Author:** ![eduardodeoh](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/eduardodeoh/32/88_2.png) [@eduardodeoh](https://discourse.dry-rb.org/u/eduardodeoh)\
**Post date:** [July 24, 2018, 10:22pm UTC](https://discourse.dry-rb.org/t/dry-transaction-invalid-result-from-around-step-adapter/589/3 "2018-07-24T22:22:14Z")

</div>

@SheepD did you use something like that with Rails ?

```auto
def db_transaction(input, &block)
        result = nil

        ActiveRecord::Base.transaction do
          result = block.(Success(input))
          raise ActiveRecord::Rollback if result.failure?
        end

        result
      end

```

---

<div class="post-metadata">

**Author:** ![SheepD](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@SheepD](https://discourse.dry-rb.org/u/SheepD)\
**Post date:** [July 25, 2018, 5:45am UTC](https://discourse.dry-rb.org/t/dry-transaction-invalid-result-from-around-step-adapter/589/4 "2018-07-25T05:45:14Z")

</div>

thanks @eduardodeoh, that is a better solution than what i came up with.
