-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
Conversation
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
a80b157
to
cead3e5
Compare
@carlosantoniodasilva To be clear: this PR should fix those stack level too deep errors, right? |
@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. |
OK, let's see how this one goes. Thank you @carlosantoniodasilva! |
🤞🙌 thank you! |
This has now been released in 1.8.9. |
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 skipI18n'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 afterskipping 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:
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 typingHash.new.method(:except)
would hang, and runningrails server
would raise the stack error, without the change here. More info about my testing.