-
Notifications
You must be signed in to change notification settings - Fork 93
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
HashWithIndifferentAccess causing unexpected behavior #66
Comments
Hi @michaelherold, I'm a little confused. Do you mean that an |
Yes, that's correct.
This process starts at command.rb:58. If that args hash is kept as a normal The comment on the cast at hash_filter.rb:86 says that "we always want a hash with indifferent access". My question is: why? Is it merely convenience? If so, why don't we just settle on a key-type (i.e. either string or symbol) and cast all of the arg keys as such? It's not clear to me why we need a hash with indifferent access. |
Postel's Law, perhaps? Agree both that it's annoying and that it's a little fiddly to fix. Hacky I know, but would recreating the |
Another cheeky solution that just occurred to me. Utterly untested:
With your original example becoming
Although this might only work if you only have one input... |
Thanks for the replies. The cheeky one got a laugh out of me. 👍 I fixed this specific issue by changing the constraint to a Hash, which works but feels awful hacky to me. I'd rather just be able to say what I mean, so I thought I'd file the bug. I was experimenting this evening with replacing the The bad thing about this approach is that it requires a lot of rework on the test suite, since the tests rely on the Is this something that the maintainers would be interested in? Since it's turning out to be non-trivial, I'd rather not sink more time into it if it's nothing something anyone else would find useful. |
No idea, I'm just a regular punter :) @cypriss ? |
The same thing occurs when a :0 > duck = Hashie::Mash.new(hello: 'world')
{
"hello" => "world"
}
:0 > duck.respond_to?(:hello)
true
:0 > class Test < Mutations::Command
:0 * required do
:0 * duck :test, methods: %w(hello)
:0 * end
:0 * def execute
:0 * end
:0 * end
:execute
:0 > Test.run!(test: duck)
Mutations::ValidationException: Test is invalid |
@jkogara The same reasoning applies: by the time |
When using a
ModelFilter
with anOmniAuth::AuthHash
(from the omniauth gem) as the expected class, theMutation::Command
fails because the auth hash is cast to aHashWithIndifferentAccess
.You can see some examples in this repo. Here's a short example inline as well:
I've started work on a fix that casts all input names to symbols, but it causes a lot of specs to need some tweaks and would not be backwards-compatible. Would such a solution be adequate? It seems like there is not really a need for HashWithIndifferentAccess, since it's overkill for the use that it's being put to.
The text was updated successfully, but these errors were encountered: