Skip to content

Comments

Really deprecate comparing AC::Parameters with a hash#44812

Merged
tenderlove merged 1 commit intomainfrom
really-deprecate
Mar 31, 2022
Merged

Really deprecate comparing AC::Parameters with a hash#44812
tenderlove merged 1 commit intomainfrom
really-deprecate

Conversation

@tenderlove
Copy link
Member

PR #23733 was supposed to deprecate and remove the ability to compare
Hash objects with AC::Parameters objects. Unfortunately it seems that
we still accidentally support that.

This PR adds a deprecation warning so that we can remove it in the
future.

Unfortunately the deprecation message is showing for a few tests and I'm not 100% sure how we should proceed.

We are delegating some methods to the underlying hash, but other methods have their own implementation.

One specific example is ActionController::Parameters#values vs ActionController::Parameters#each_value. These two methods can hand back different objects:

require "minitest/autorun"
require "active_support/all"
require "action_controller/metal/strong_parameters"

class ParametersMemberTest < Minitest::Test
  def test_ok
    hash = { "foo" => { "bar" => :baz } }
    params = ActionController::Parameters.new(hash)
    p params.values
    p params.each_value.to_a
  end
end

Output is:

$ bundle exec ruby -I activesupport/lib/:actionpack/lib thing.rb
Run options: --seed 23907

# Running:

[{"bar"=>:baz}]
[#<ActionController::Parameters {"bar"=>:baz} permitted: false>]
.

Finished in 0.000400s, 2499.9999 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 0 errors, 0 skips

The above behavior leads to an odd case where params.values doesn't equal params.each_value.to_a and we have a test for that here.

IMO we need to stop delegating any methods to the underlying hash, or at least drastically restrict them, but I'm somewhat worried about compatibility.

PR #23733 was supposed to deprecate and remove the ability to compare
Hash objects with AC::Parameters objects.  Unfortunately it seems that
we still accidentally support that.

This PR adds a deprecation warning so that we can remove it in the
future.
@rails-bot rails-bot bot added the actionpack label Mar 31, 2022
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.

2 participants