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

Error with inputs method after 4.0 release #493

Closed
spencersteiner opened this issue Jan 11, 2021 · 5 comments
Closed

Error with inputs method after 4.0 release #493

spencersteiner opened this issue Jan 11, 2021 · 5 comments
Labels

Comments

@spencersteiner
Copy link
Contributor

Hey there! Thanks for your awesome work on this project, I absolutely love using this library.

I noticed my tests started breaking today (I've been using the v4.0.0 tag for a number of months) and I'm getting the following error:

inputs must be a hash or ActionController::Parameters

I wasn't sure if it was just my app or configuration, so I created a fresh new rails environment using ruby 2.6 and Rails 6. I created your Add and AddAndDouble classes from the readme examples, and got the same error for the line compose(Add, inputs) * 2 when calling AddAndDouble.run!(x: 1, y: 1)

I also noticed the release notes mention a change to inputs and wasn't sure if that is related to this.

Do I need to be handling inputs differently for 4.0, or is this a bug?

@VetLee
Copy link

VetLee commented Feb 16, 2021

A similar problem. Temporarily used inputs.to_h

@spencersteiner
Copy link
Contributor Author

@VetLee Glad I'm not the only one! I'm converting the inputs to hash just as you are for the time being.

@AaronLasseigne
Copy link
Owner

My environment here is slightly different but it's close and it looks like it works fine:

CleanShot 2021-04-03 at 17 05 35@2x

Can you give me a better understanding of what you're doing to cause it to fail?

@spencersteiner
Copy link
Contributor Author

@AaronLasseigne Ah, I could have been clearer: the issue pertains to the inputs hash specifically. Referencing the individual inputs by name works fine. Are you able to replicate with the example code like I have below? (I executed in a rails 6.0.3.6 environment).

I'm also happy to create a repo with a clean rails environment where it can be replicated if that's preferable!

Screen Shot 2021-04-05 at 1 45 30 PM

@gblair
Copy link

gblair commented Jun 17, 2021

Just chiming in because I noticed (I think) this same issue today after upgrading to the latest version.

It looks like the type returned from the inputs method inside an interaction is ActiveInteraction::Inputs which tosses an error in ActiveInteraction::Base#normalize_inputs! (e.g.) when used with compose:

def normalize_inputs!(inputs)
  return inputs if inputs.is_a?(Hash)

  parameters = 'ActionController::Parameters'
  klass = parameters.safe_constantize
  return inputs.to_unsafe_h if klass && inputs.is_a?(klass)

  raise ArgumentError, "inputs must be a hash or #{parameters}"
end

This is a problem when using the inputs method inside an interaction to share inputs with a composed interaction. For now, rather than rewriting all my compose calls with inputs.to_h I'm just rolling back to 3.8.3. I could hazard a PR for this, if you just want to allowlist the ActiveInteraction::Inputs as well -- just say the word!

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

No branches or pull requests

4 participants