-
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
[ActiveRecord] PostgreSQL Adapter skips update on CIDR column when only netmask is changed #51582
Labels
Comments
taketo1113
added a commit
to taketo1113/rails
that referenced
this issue
Apr 22, 2024
4 tasks
taketo1113
added a commit
to taketo1113/rails
that referenced
this issue
Apr 23, 2024
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to reproduce
I cannot provide an executable test case of the exact problem since PostgreSQL cannot run in-memory easily, but I can demonstrate the underlying problem.
When I have a CIDR column in a PostgreSQL database with value
1.1.1.0/24
and I change it to1.1.1.0/25
, it will not be updated on save.Expected behavior
When
old_value
is in any way different fromnew_value
, thenchanged?
should returntrue
.Actual behavior
old_value
(1.1.1.0/24) is treated as the same asnew_value
(1.1.1.0/25) which is obviously not the case.Further notes
The cause of this problem is, that
IPAddr#==
ignores the netmask for its comparison.To solve the problem, it is necessary to overwrite
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cidr#changed?
so it does not useIPAddr#==
anymore.IPAddr#eql?
is suitable for this, but may be overkill. There is an open issue addressing thatIPAddr#==
does not work as expected ruby/ipaddr#21It is possible to monkey-patch
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cidr
to work as expected:System configuration
Rails version: 7.1.3.2
Ruby version: 3.3.0
The text was updated successfully, but these errors were encountered: