-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Unsafe implementation of ==(other)
method of AttributeSet
#49670
Comments
Can you create a reproduction test script using https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_gem.rb template? |
Here it is: # frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "activerecord", "~> 7.1.0"
gem "sqlite3"
end
require "active_record"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
class BugTest < Minitest::Test
def test_attribute_set
my_attribute_set = ActiveModel::AttributeSet.new({})
assert_equal false, my_attribute_set == nil
end
end |
Would you like to open a PR? An additional check for |
Yep, I will do it. |
Update to the suggestion: instead of |
|
Good point! @DmitryPogrebnoy How did you got that error? Can you share a real-world example? |
I have a debugger gem that does object introspection. And there is a nil check in there like this: Also, the current implementation of the From my point of view this is definitely a bug. I don't know why we need to keep it just because this is not a part of public api. |
Make `==(other)` method of AttributeSet safe #49670
Make `==(other)` method of AttributeSet safe #49670
Steps to reproduce
There is a problem with the implementation of method
==(other)
of AttributeSet.See
rails/activemodel/lib/active_model/attribute_set.rb
Lines 106 to 108 in e4e2426
So if you try to use it like this:
attribute_set == null
, then you get an NoMethodException.The steps for reproduction are clear:
AttributeSet
orLazyAttributeSet
.my_attribute_set
. Invoke the code belowExpected behavior
It should return false. And be safe for any other instances
Actual behavior
NoMethodException is thrown
System configuration
Rails version: Rails 7
Ruby version: 2.7.8
The text was updated successfully, but these errors were encountered: