Skip to content

Comments

Ensure that Hash and ActionController::Parameters are equal both ways.#23711

Closed
pschambacher wants to merge 1 commit intorails:masterfrom
pschambacher:pschambacher/equal_works_both_ways
Closed

Ensure that Hash and ActionController::Parameters are equal both ways.#23711
pschambacher wants to merge 1 commit intorails:masterfrom
pschambacher:pschambacher/equal_works_both_ways

Conversation

@pschambacher
Copy link
Contributor

Follow-up for #23167 by @maclover7
It fixed ActionController::Parameters == Hash but not Hash == ActionController::Parameters.

I think that a == b should be the same as b == a so here's a fix.
The test failed without the lib change.

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@schneems
Copy link
Member

I don't like modifying builtin classes like this. This will slow down hash equality comparison considerably around non-parameter equality comparisons.

ActionController::Parameters is not a hash, so we should not expect it to be equal to one. If you were relying on this behavior before i would think wrapping it would be the best way forwards

ActionController::Parameters.new(hash) == params

Or simply

params == hash

While I agree that technically a == b should always be the same as b == a, i'm not sure the implementation merits the technical completeness. I would rather we deprecate the other behavior and give a warning

You are comparing equality between a `ActionController::Parameters.new` and a `Hash`. In the future please only do comparisons between instances of `ActionController::Parameters` if you need to compare it to a hash please convert it using `ActionController::Parameters#new

@maclover7
Copy link
Contributor

Concur with @schneems - this seems unnecessary. I think it does make sense to possibly include a deprecation warning, which will be removed in 5.1.

@pschambacher
Copy link
Contributor Author

This will make migrating tests a big pain.
If you have something like object.expects(:update_attributes).with(some_hash), you'll have to rewrite everything to wrap it in ActionController::Parameters. If that's what you think should happen then this PR can be closed.

@rafaelfranca
Copy link
Member

Yes. Agree this change is unnecessary. Thank you for the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants