-
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
Fix PostgreSQL Cidr#change?
to compare with address prefix
#51633
Conversation
activerecord/lib/active_record/connection_adapters/postgresql/oid/cidr.rb
Outdated
Show resolved
Hide resolved
ddff849
to
19839cc
Compare
activerecord/lib/active_record/connection_adapters/postgresql/oid/cidr.rb
Outdated
Show resolved
Hide resolved
efeb853
to
2eac97d
Compare
activerecord/lib/active_record/connection_adapters/postgresql/oid/cidr.rb
Show resolved
Hide resolved
2eac97d
to
acc277b
Compare
Fix PostgreSQL `Cidr#change?` to compare with address prefix
Backported to the |
@yahonda This needs a changelog as its a change in behavior? |
Let me add a change log entry for this change. Thanks for the heads-up. |
Follow up rails#51633 Co-authored-by: Taketo Takashima <t.taketo1113@gmail.com>
Opened #51742 to add a changelog entry for this change. |
@yahonda @taketo1113 I'm on Rails 7-1 stable. and this makes my production app crash under certain circumstances. when |
Honestly I wish I could reproduce the bug (it's in production) but it's so mystical. all I can say is, it's related to this PR and it was done on a "ActiveRecord#save" call. on an unpersisted instance (probably the reason why but what's mystical to me is why it goes through the |
@taketo1113 @yahonda I finally managed to recreate the issue It's due to the fact that this part helped me get less confused and better investigate and reproduce the issue # frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
# If you want to test against edge Rails replace the previous line with this:
gem "rails", github: "rails/rails", branch: "main"
gem "pg"
end
require "active_record"
require "minitest/autorun"
require "logger"
db_config = {
adapter: 'postgresql',
database: 'inet_cidr_test',
host: 'localhost', # Change this to your PostgreSQL host
port: 5432,
username: 'postgres', # Change this to your PostgreSQL username
password: 'postgres' # Change this to your PostgreSQL password
}
ActiveRecord::Base.establish_connection(db_config.except(:database))
ActiveRecord::Base.connection.drop_database(db_config[:database]) rescue nil
ActiveRecord::Base.connection.create_database(db_config[:database])
ActiveRecord::Base.establish_connection(db_config)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.inet :ip_address
end
end
class User < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_ip_address_with_empty_string
User.create!(ip_address: '')
end
end |
@chaadow if you haven't already, please open up a separate/new issue to help track this. |
I confirmed to reproduce issue and created PR (#51758) |
Follow up rails#51633 Co-authored-by: Taketo Takashima <t.taketo1113@gmail.com>
Follow up rails#51633 Co-authored-by: Taketo Takashima <t.taketo1113@gmail.com>
Motivation / Background
This Pull Request has been created because fixes #51582
Detail
This Pull Request changes to override
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cidr#changed?
.It added to compare address prefix of IPAddr class.
Additional information
I’m proposing to fix
IPAddr#==
comparing address prefix for the cause of this problem.ruby/ipaddr#69
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]