Skip to content

fail! raises self, which is an OpenStruct and to_s on the exception loads ActiveRecord Relations #185

@thekendalmiller

Description

@thekendalmiller

We recently updated the interactor gem and ran into an interesting issue where fail! would trigger any ActiveRecord relations passed in the context to be evaluated.

The issue ended up being because of a rescue in one of our interactors doing exception.to_s'. And because the context is an OpenStruct, to_s would print out the results of the ActiveRecord relations because for each key, it does value.inspect

Here is a very simple reproduction that works in console.

class SimpleTest
  include Interactor

  def call
    begin
      context.fail!
    rescue => e
      puts e.to_s
    end
  end
end

SimpleTest.call(offices: Somemodel.all, users: AnotherModel.all);

The fix we are using is adding a to_s in Interactor::Failure. If someone wants to access the context, it's already on Failure here: https://github.com/collectiveidea/interactor/blob/master/lib/interactor/error.rb#L27

Would this fix be something you are interested in having a Pull Request for? If so I can submit one.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions