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

Add CI for ruby3.0 #70

Merged
merged 3 commits into from
Jan 26, 2021
Merged

Add CI for ruby3.0 #70

merged 3 commits into from
Jan 26, 2021

Conversation

alpaca-tc
Copy link
Contributor

@alpaca-tc alpaca-tc commented Jan 21, 2021

Add ruby 3.0 support 🎉

  • NOTE: Ruby 3.0 works fine on only >= 6.1.0
  • Update minitest because old version doesn't support ruby3.0
  • Change refinements for #dup method

why I changed refinements for #dup

In the case of using ruby3.0 & rails6.1.0, when you call ActiveRecord::Base.establish_connection, the process will freeze and stop working. I investigated this issue, I found that refinements for #dup causes this problem.
I think that Ruby is not tested well enough for refinements because the override #dup with refinements is not recommended way.

related: https://bugs.ruby-lang.org/issues/17494

@auto-assign auto-assign bot requested review from 16bitidol and motsat January 21, 2021 21:32
Comment on lines 73 to 80
def initialize_dup(other)
# MEMO: Do not copy `swapped_id`
if instance_variable_defined?(:@_swapped_id)
remove_instance_variable(:@_swapped_id)
end

super
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it break when #initialize_dup is defined in user code?

# User code
class User < ApplicationRecord
  include

  def initialize_dup
    # other implemented
  end
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, doesn't this implementation also change the behavior of code that calls #dup elsewhere?

Copy link
Contributor Author

@alpaca-tc alpaca-tc Jan 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it break when #initialize_dup is defined in user code?

It isn't problem because it is the same as #dup. Normally user shouldn't define initialize_dup without super.

Also, doesn't this implementation also change the behavior of code that calls #dup elsewhere?

Right. I just thought that #dup should clear instance scoped variables but it is not necessary as you said.
I just resolved this issue by replacing refine Object with refine ActiveRecord::Base. This way is the most little changes.

@osyo-manga
Copy link
Collaborator

Thanks for PR :)

why I removed refinements for #dup

Yes, I believe this is a bug in Ruby (or other gem).
We are investigating the specific cause.
A simple way to deal with it would be to define #dup with a different name
Is it possible to change the implementation in that way?

see:


before_instance = current_valid_record.dup

duplicated_instance = self.class.find_at_time(target_datetime, self.id).dup

@osyo-manga
Copy link
Collaborator

Great!! Thank!!
@alpaca-tc I have merged #69. Can you rebase ?

Don't refine classes that it isn't necessary.
As a technical issue, overriding Object#dup causes a problem of stopping
`ActiveRecord::Base.establish_connection` in Ruby 3.0.
I will try to continue to investigate this issue.
@alpaca-tc
Copy link
Contributor Author

@osyo-manga done :)

@osyo-manga osyo-manga self-requested a review January 25, 2021 01:46
Copy link
Collaborator

@osyo-manga osyo-manga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

@f440 f440 self-requested a review January 26, 2021 05:45
Copy link
Member

@f440 f440 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

@f440 f440 merged commit afc8643 into kufu:master Jan 26, 2021
@alpaca-tc alpaca-tc deleted the ruby_3_0 branch January 28, 2021 04:46
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 this pull request may close these issues.

None yet

3 participants