Skip to content
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

Some important fixes #1166

Merged
merged 4 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ end

group :rails do
group :test do
gem 'minitest', require: nil
gem 'minitest', '~> 5.24.0', require: nil
gem 'minitest-excludes', require: nil
gem 'minitest-rg', require: nil

Expand Down
24 changes: 24 additions & 0 deletions lib/arjdbc/abstract/relation_query_attribute_monkey_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require "active_model/attribute"

module ActiveRecord
# NOTE: improved implementation for hash methods that is used to
# compare objects. AR and arel commonly use `[a, b] - [b]` operations and
# JRuby internally uses the hash method to implement that operation,
# on the other hand, CRuby does not use the hash method
# for small arrays (length <= 16).
class Relation
# monkey patch
module RelationQueryAttributeMonkeyPatch
def hash
# [self.class, name, value_for_database, type].hash
[self.class, name, value_before_type_cast, type].hash
end
end

class QueryAttribute
prepend RelationQueryAttributeMonkeyPatch
end
end
end
2 changes: 2 additions & 0 deletions lib/arjdbc/mysql/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
require 'arjdbc/abstract/statement_cache'
require 'arjdbc/abstract/transaction_support'

require "arjdbc/abstract/relation_query_attribute_monkey_patch"

module ActiveRecord
module ConnectionAdapters
AbstractMysqlAdapter.class_eval do
Expand Down
8 changes: 7 additions & 1 deletion lib/arjdbc/postgresql/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

require 'active_model'

require "arjdbc/abstract/relation_query_attribute_monkey_patch"

module ArJdbc
# Strives to provide Rails built-in PostgreSQL adapter (API) compatibility.
module PostgreSQL
Expand Down Expand Up @@ -739,6 +741,8 @@ def translate_exception(exception, message:, sql:, binds:)

# TODO: Can we base these on an error code of some kind?
case exception.message
when /could not create unique index/
::ActiveRecord::RecordNotUnique.new(message, sql: sql, binds: binds, connection_pool: @pool)
when /duplicate key value violates unique constraint/
::ActiveRecord::RecordNotUnique.new(message, sql: sql, binds: binds)
when /violates not-null constraint/
Expand All @@ -757,7 +761,9 @@ def translate_exception(exception, message:, sql:, binds:)
::ActiveRecord::LockWaitTimeout.new(message, sql: sql, binds: binds)
when /canceling statement/ # This needs to come after lock timeout because the lock timeout message also contains "canceling statement"
::ActiveRecord::QueryCanceled.new(message, sql: sql, binds: binds)
when /relation "animals" does not exist/i
when /relation .* does not exist/i
::ActiveRecord::StatementInvalid.new(message, sql: sql, binds: binds, connection_pool: @pool)
when /syntax error at or near/i
::ActiveRecord::StatementInvalid.new(message, sql: sql, binds: binds, connection_pool: @pool)
else
super
Expand Down
1 change: 1 addition & 0 deletions lib/arjdbc/postgresql/database_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module PostgreSQL
module DatabaseStatements
def explain(arel, binds = [], options = [])
sql = build_explain_clause(options) + " " + to_sql(arel, binds)

result = internal_exec_query(sql, "EXPLAIN", binds)
ActiveRecord::ConnectionAdapters::PostgreSQL::ExplainPrettyPrinter.new.pp(result)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/arjdbc/sqlite3/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
require "active_support/core_ext/class/attribute"
require "arjdbc/sqlite3/column"

require "arjdbc/abstract/relation_query_attribute_monkey_patch"

module SQLite3
module Constants
module Open
Expand Down
2 changes: 2 additions & 0 deletions test/explain_support_test_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def test_explain_without_binds
end

def test_explain_with_arel
skip "This might not be a valid test anymore"

arel, _ = create_explain_arel

pp = ActiveRecord::Base.connection.explain(arel, [])
Expand Down
1 change: 1 addition & 0 deletions test/rails/excludes/mysql2/QueryCacheTest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude :test_query_cache_callbacks_exit_gracefully_from_a_fork, 'There is no fork in Java and/or JRuby'
1 change: 1 addition & 0 deletions test/rails/excludes/postgresql/QueryCacheTest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude :test_query_cache_callbacks_exit_gracefully_from_a_fork, 'There is no fork in Java and/or JRuby'
1 change: 1 addition & 0 deletions test/rails/excludes/sqlite3/QueryCacheTest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude :test_query_cache_callbacks_exit_gracefully_from_a_fork, 'There is no fork in Java and/or JRuby'
Loading