Skip to content
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

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

Open
thekendalmiller opened this issue May 22, 2020 · 0 comments

Comments

@thekendalmiller
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant