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

Prevent overwriting Hash#except method present in Ruby 3+ #557

Merged
merged 1 commit into from
Feb 12, 2021

Conversation

carlosantoniodasilva
Copy link
Member

@carlosantoniodasilva carlosantoniodasilva commented Feb 6, 2021

Note: this was updated to be based on #558 which fixes the build for the Rails main matrix.

Ruby 3+ introduced Hash#except method natively [1], so we can skip
I18n's custom implementation here if the method is already defined.
This follows the same Rails convention [2].

Note: This seems to be causing a stack level too deep (SystemStackError)
with a specific set of Gemfiles under Ruby 3, reported to SimpleForm
originally [3]. I haven't been able to fully narrow it down after some
initial investigation, nor reproduce it without the given set of gems in
the Gemfile reported, but it seems there's some interactions between
those gems, and combined with the fact that Ancestry loads I18n early on
to setup the load path [4], is possibly causing calls to Hash#except
to hang or raise with the stack level too deep error, and after
skipping the method re-declaration here it's not reproducible anymore.

[1] https://bugs.ruby-lang.org/issues/15822
[2] https://github.com/rails/rails/blob/5f3ff60084ab5d5921ca3499814e4697f8350ee7/activesupport/lib/active_support/core_ext/hash/except.rb#L12-L14
[3] heartcombo/simple_form#1724
steps to reproduce issue: heartcombo/simple_form#1724 (comment)
[4] https://github.com/stefankroes/ancestry/blob/71fe7042791f5943b5370240e4c6068dce73233d/lib/ancestry.rb#L9-L10


Reproducing

This is from the original SimpleForm issue.

Minimal Gemfile used to reproduce:

source 'https://rubygems.org'
ruby '3.0.0'

gem 'rails', '~> 6.1.1'
gem 'sqlite3', '~> 1.4'
gem "puma"
gem "listen"

gem "ancestry", "3.2.1"
gem "simple_form", "5.0.3"
gem "hashie", "4.1.0"
gem "pry-byebug", "3.9.0"

Demo app: https://github.com/khustochka/sf_ancestry_test (I haven't tested this one directly myself, I had an app set up with that Gemfile above)

Simply going to rails console and typing Hash.new.method(:except) would hang, and running rails server would raise the stack error, without the change here. More info about my testing.

@carlosantoniodasilva carlosantoniodasilva self-assigned this Feb 6, 2021
Ruby 3+ introduced `Hash#except` method natively [1], so we can skip
I18n's custom implementation here if the method is already defined.
This follows the same Rails convention [2].

Note: This seems to be causing a `stack level too deep (SystemStackError)`
with a specific set of Gemfiles under Ruby 3, reported to `SimpleForm`
originally [3].  I haven't been able to fully narrow it down after some
initial investigation, nor reproduce it without the given set of gems in
the Gemfile reported, but it seems there's some interactions between
those gems, and combined with the fact that Ancestry loads I18n early on
to setup the load path [4], is possibly causing calls to `Hash#except`
to hang or raise with the `stack level too deep` error, and after
skipping the method re-declaration here it's not reproducible anymore.

[1] https://bugs.ruby-lang.org/issues/15822
[2] https://github.com/rails/rails/blob/5f3ff60084ab5d5921ca3499814e4697f8350ee7/activesupport/lib/active_support/core_ext/hash/except.rb#L12-L14
[3] heartcombo/simple_form#1724
    steps to reproduce issue: heartcombo/simple_form#1724 (comment)
[4] https://github.com/stefankroes/ancestry/blob/71fe7042791f5943b5370240e4c6068dce73233d/lib/ancestry.rb#L9-L10
@radar
Copy link
Collaborator

radar commented Feb 11, 2021

@carlosantoniodasilva To be clear: this PR should fix those stack level too deep errors, right?

@carlosantoniodasilva
Copy link
Member Author

@radar yes, it should, hopefully. I tried a few things to repro on I18n alone but couldn't find a way. In the test app based one the Gemfile above this fix worked to prevent the issue, and the person there who helped me repro commented back that their app worked against this branch on Ruby 3.

@radar
Copy link
Collaborator

radar commented Feb 12, 2021

OK, let's see how this one goes. Thank you @carlosantoniodasilva!

@radar radar merged commit 3951eee into master Feb 12, 2021
@radar radar deleted the ca-except-ruby3 branch February 12, 2021 20:11
@carlosantoniodasilva
Copy link
Member Author

🤞🙌 thank you!

@radar
Copy link
Collaborator

radar commented Feb 12, 2021

This has now been released in 1.8.9.

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.

2 participants