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

For midnigh(00:00) only, the processing of the time type in the trilogy adapter is broken. #48736

Closed
tmimura39 opened this issue Jul 14, 2023 · 1 comment

Comments

@tmimura39
Copy link

tmimura39 commented Jul 14, 2023

Steps to reproduce

For midnigh(00:00) only, the processing of the time type in the trilogy adapter is broken.
※ An example of mysql2 is also included for reference.

# 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", github: "rails/rails", branch: "main"
  gem "trilogy"
  gem "mysql2"
end

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

ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(adapter: "trilogy", database: "test", username: "root", host: '127.0.0.1', port: 3306)

ActiveRecord::Schema.define do
  create_table :posts, force: true do |t|
    t.time :time_column
  end
end

class Post < ActiveRecord::Base
end

Post.create!(time_column: '00:00')

class BugTest < Minitest::Test
  def test_mysql2
    ActiveRecord::Base.establish_connection(adapter: "mysql2", database: "test", username: "root", host: '127.0.0.1', port: 3306)
    assert_equal Post.take.time_column, Time.utc(2000, 1, 1, 0, 0)
  end

  def test_trilogy
    ActiveRecord::Base.establish_connection(adapter: "trilogy", database: "test", username: "root", host: '127.0.0.1', port: 3306)
    assert_equal Post.take.time_column, Time.utc(2000, 1, 1, 0, 0)
  end
end

Expected behavior

Both mysql2 and torilogy, 2000-01-01T00:00:00Z to be returned.

Actual behavior

In case of trilogy, nil is returned.

Failure:
BugTest#test_trilogy [midnight.rb:42]:
Expected: nil
  Actual: 2000-01-01 00:00:00 UTC

Is it a problem with Trilogy?

client = Trilogy.new(host: "127.0.0.1", port: 13306, username: "root")
client.change_db('test')
client.query('SELECT * FROM posts;').to_a #=> [[1, nil]]

I was wondering where to report this. activerecord-trilogy-adapter and trilogy and rails/rails.
Sorry if I am wrong.

System configuration

Rails version: v7.1.0.alpha (main@c9cdd80)

Ruby version: v3.2.2

Trilogy: v2.4.1

@matthewd
Copy link
Member

Is it a problem with Trilogy?

Yes. Thanks for the report. This was recently fixed in trilogy: trilogy-libraries/trilogy#97 -- there should be a release soon.

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

No branches or pull requests

2 participants