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

sql_mode specification is not applied in ActiveRecord v7.0.6 #54

Closed
tmimura39 opened this issue Jul 14, 2023 · 1 comment · Fixed by #56
Closed

sql_mode specification is not applied in ActiveRecord v7.0.6 #54

tmimura39 opened this issue Jul 14, 2023 · 1 comment · Fixed by #56

Comments

@tmimura39
Copy link

tmimura39 commented Jul 14, 2023

Steps to reproduce

It seems that various settings including sql_mode are not applied correctly because configure_connection is not executed.

# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "rails", "= 7.0.6"
  gem "activerecord-trilogy-adapter"
  gem "mysql2"
end

require "active_record"
require "minitest/autorun"
require "logger"

ActiveRecord::Base.logger = Logger.new(STDOUT)

class BugTest < Minitest::Test
  def test_mysql2
    ActiveRecord::Base.establish_connection(adapter: "mysql2", database: "test", username: "root", host: '127.0.0.1', port: 3306, variables: { sql_mode: "STRICT_ALL_TABLES" })
    assert_equal ActiveRecord::Base.connection.execute('SELECT @@SESSION.sql_mode;').to_a, [["STRICT_ALL_TABLES"]]
  end

  def test_trilogy
    ActiveRecord::Base.establish_connection(adapter: "trilogy", database: "test", username: "root", host: '127.0.0.1', port: 3306, variables: { sql_mode: "STRICT_ALL_TABLES" })
    assert_equal ActiveRecord::Base.connection.execute('SELECT @@SESSION.sql_mode;').to_a, [["STRICT_ALL_TABLES"]]
  end
end

Expected behavior

Both mysql2 and torilogy, sql_mode is correctly applied as specified in the DB connection settings variables.

Actual behavior

mysql2 correctly applies sql_mode.
However, trilogy applies the default sql_mode.

Failure:
BugTest#test_trilogy [main.rb:29]:
--- expected
+++ actual
@@ -1 +1 @@
-[["ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"]]
+[["STRICT_ALL_TABLES"]]

It seems to be due to the fact that the Trilogy Adapter assumes rails/rails#44591.
Current release versions, including Rails v7.0.6, do not include this fix and will not work properly.

System configuration

Rails version: v7.0.6

Ruby version: v3.2.2

trilogy version: v2.4.1

activerecord-trilogy-adapter: v3.1.0

lorint added a commit to lorint/activerecord-trilogy-adapter that referenced this issue Jul 19, 2023
lorint added a commit to lorint/activerecord-trilogy-adapter that referenced this issue Jul 19, 2023
lorint added a commit to lorint/activerecord-trilogy-adapter that referenced this issue Jul 19, 2023
lorint added a commit to lorint/activerecord-trilogy-adapter that referenced this issue Jul 19, 2023
@lorint
Copy link
Collaborator

lorint commented Jul 19, 2023

Hi, Tomohiko Mimura! Thank you for your research with this issue. Have put together PR #56 with hopes it might offer a comprehensive fix.

Many thanks for your contributions to ActiveRecord Trilogy Adapter!

lorint added a commit to lorint/activerecord-trilogy-adapter that referenced this issue Jul 19, 2023
@lorint lorint linked a pull request Aug 6, 2023 that will close this issue
bensheldon added a commit that referenced this issue Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants