You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ ruby -v
jruby 9.4.6.0 (3.1.4) 2024-02-20 576fab2c51 OpenJDK 64-Bit Server VM 21.0.1 on 21.0.1 +jit [arm64-darwin]
$ uname -a
Darwin janko.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:41 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8103 arm64
I'm using activerecord-jdbc-adapter version 70.2.
Expected Behavior
I expected same raw connection to be considered identical by JRuby when using as hash key with compare_by_identity turned on.
The above script prints out nil instead of "1", because JRuby considers the connection objects different, even though they have the same #object_id and #hash, and are equal in terms of #==, #eql? and #equal?.
I discovered this while debugging test failures in sequel-activerecord_connection gem, which enables Sequel to reuse Active Record's DB connection. Sequel internally stores transaction state in a hash with compare_by_identity turned on, where hash keys are raw connection objects. Sequel's JDBC adapter itself doesn't appear to have any issues, this only happens if I swap retrieving the connection to go through Active Record.
I could disable compare_by_identity in the sequel-activerecord_connection gem when using JRuby, but I thought I'd report it since I already did the hard work of debugging this issue, and found it surprising that two objects can communicate they're identical but aren't always 😅
The text was updated successfully, but these errors were encountered:
Environment Information
$ ruby -v jruby 9.4.6.0 (3.1.4) 2024-02-20 576fab2c51 OpenJDK 64-Bit Server VM 21.0.1 on 21.0.1 +jit [arm64-darwin] $ uname -a Darwin janko.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:41 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8103 arm64
I'm using
activerecord-jdbc-adapter
version70.2
.Expected Behavior
I expected same raw connection to be considered identical by JRuby when using as hash key with
compare_by_identity
turned on.Actual Behavior
The above script prints out
nil
instead of"1"
, because JRuby considers the connection objects different, even though they have the same#object_id
and#hash
, and are equal in terms of#==
,#eql?
and#equal?
.I discovered this while debugging test failures in
sequel-activerecord_connection
gem, which enables Sequel to reuse Active Record's DB connection. Sequel internally stores transaction state in a hash withcompare_by_identity
turned on, where hash keys are raw connection objects. Sequel's JDBC adapter itself doesn't appear to have any issues, this only happens if I swap retrieving the connection to go through Active Record.I could disable
compare_by_identity
in thesequel-activerecord_connection
gem when using JRuby, but I thought I'd report it since I already did the hard work of debugging this issue, and found it surprising that two objects can communicate they're identical but aren't always 😅The text was updated successfully, but these errors were encountered: