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

ruby 3.4.0dev deprecates OpenStruct #561

Closed
yahonda opened this issue Apr 10, 2024 · 1 comment · Fixed by #562
Closed

ruby 3.4.0dev deprecates OpenStruct #561

yahonda opened this issue Apr 10, 2024 · 1 comment · Fixed by #562

Comments

@yahonda
Copy link
Member

yahonda commented Apr 10, 2024

jbuilder has OpenStruct that will be deprecated in Ruby 3.4.0dev.
https://bugs.ruby-lang.org/issues/20309

  • foo.rb
require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"
  gem "jbuilder"
end
p RUBY_VERSION

Expected behavior

It should not show any warnings as executed against Ruby 3.3.0.

$ ruby foo.rb
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
"3.3.0"

Actual behavior

It raises warning: ostruct was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec. warning.

$ ruby foo.rb
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
/home/yahonda/.rbenv/versions/trunk/lib/ruby/gems/3.4.0+0/gems/jbuilder-2.11.5/lib/jbuilder.rb:7: warning: ostruct was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec.
"3.4.0"
@yahonda
Copy link
Member Author

yahonda commented Apr 10, 2024

Here are the lines OpenStruct is used.

require 'ostruct'

NON_ENUMERABLES = [ ::Struct, ::OpenStruct ].to_set

yahonda added a commit to yahonda/rails that referenced this issue Apr 10, 2024
…4.0dev

This commit addresses Rails Nightly CI failure
at https://buildkite.com/rails/rails-nightly/builds/391#018ec54f-a2ef-40de-9749-6cc3ecae4ebd/1368-1376

```ruby
$ ruby -v
ruby 3.4.0dev (2024-04-09T16:29:01Z master 0107954f25) [x86_64-linux]
$ bin/test test/command/help_integration_test.rb:33
Run options: --seed 3363

F

Failure:
Rails::Command::HelpIntegrationTest#test_prints_help_via_`X:help`_command_when_running_`X`_and_`X:X`_command_is_not_defined [test/command/help_integration_test.rb:37]:
--- expected
+++ actual
@@ -1,4 +1,5 @@
-"Commands:
+"/home/yahonda/.rbenv/versions/trunk/lib/ruby/gems/3.4.0+0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34: warning: ostruct was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec.
+Commands:
   bin/rails dev:cache           # Toggle development mode caching on/off
   bin/rails dev:help [COMMAND]  # Describe available commands or one specific...

bin/test test/command/help_integration_test.rb:33

Finished in 0.738986s, 1.3532 runs/s, 1.3532 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
$
```

This commit can be reverted once both rack and jbuilder take care of it.

Related to
rack/rack#2166
rails/jbuilder#561
@dhh dhh closed this as completed in #562 Apr 29, 2024
dhh pushed a commit that referenced this issue Apr 29, 2024
This commit uses OpenStruct only if available because of the following reasons:

- Starting from Ruby 3.4.0dev, Using `ostruct` raises the following warning.
> ostruct was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec.

- And when the warning category is `:performance` it also raises this warning.
> "OpenStruct use is discouraged for performance reasons

Refer to
https://bugs.ruby-lang.org/issues/20309
ruby/ruby#10428
ruby/ostruct#56
Fix #561
fractaledmind pushed a commit to fractaledmind/rails that referenced this issue May 13, 2024
…4.0dev

This commit addresses Rails Nightly CI failure
at https://buildkite.com/rails/rails-nightly/builds/391#018ec54f-a2ef-40de-9749-6cc3ecae4ebd/1368-1376

```ruby
$ ruby -v
ruby 3.4.0dev (2024-04-09T16:29:01Z master 0107954f25) [x86_64-linux]
$ bin/test test/command/help_integration_test.rb:33
Run options: --seed 3363

F

Failure:
Rails::Command::HelpIntegrationTest#test_prints_help_via_`X:help`_command_when_running_`X`_and_`X:X`_command_is_not_defined [test/command/help_integration_test.rb:37]:
--- expected
+++ actual
@@ -1,4 +1,5 @@
-"Commands:
+"/home/yahonda/.rbenv/versions/trunk/lib/ruby/gems/3.4.0+0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34: warning: ostruct was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec.
+Commands:
   bin/rails dev:cache           # Toggle development mode caching on/off
   bin/rails dev:help [COMMAND]  # Describe available commands or one specific...

bin/test test/command/help_integration_test.rb:33

Finished in 0.738986s, 1.3532 runs/s, 1.3532 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
$
```

This commit can be reverted once both rack and jbuilder take care of it.

Related to
rack/rack#2166
rails/jbuilder#561
xjunior pushed a commit to xjunior/rails that referenced this issue Jun 9, 2024
…4.0dev

This commit addresses Rails Nightly CI failure
at https://buildkite.com/rails/rails-nightly/builds/391#018ec54f-a2ef-40de-9749-6cc3ecae4ebd/1368-1376

```ruby
$ ruby -v
ruby 3.4.0dev (2024-04-09T16:29:01Z master 0107954f25) [x86_64-linux]
$ bin/test test/command/help_integration_test.rb:33
Run options: --seed 3363

F

Failure:
Rails::Command::HelpIntegrationTest#test_prints_help_via_`X:help`_command_when_running_`X`_and_`X:X`_command_is_not_defined [test/command/help_integration_test.rb:37]:
--- expected
+++ actual
@@ -1,4 +1,5 @@
-"Commands:
+"/home/yahonda/.rbenv/versions/trunk/lib/ruby/gems/3.4.0+0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34: warning: ostruct was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec.
+Commands:
   bin/rails dev:cache           # Toggle development mode caching on/off
   bin/rails dev:help [COMMAND]  # Describe available commands or one specific...

bin/test test/command/help_integration_test.rb:33

Finished in 0.738986s, 1.3532 runs/s, 1.3532 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
$
```

This commit can be reverted once both rack and jbuilder take care of it.

Related to
rack/rack#2166
rails/jbuilder#561
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.

1 participant