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

[WIP] Upgrade to Ruby 3.3 #3864

Closed
wants to merge 19 commits into from
Closed

[WIP] Upgrade to Ruby 3.3 #3864

wants to merge 19 commits into from

Conversation

mayorova
Copy link
Contributor

@mayorova mayorova commented Aug 8, 2024

This was an experiment to see whether it could replace #3847 easily, but it turned out to be more effort than I was hoping for...

Some of the errors I saw and tried to fix:

/home/dmayorov/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/gems/css_parser-1.12.0/lib/css_parser/regexps.rb:11:in `initialize': wrong number of arguments (given 3, expected 1..2) (ArgumentError)

  RE_NON_ASCII = Regexp.new('([\x00-\xFF])', Regexp::IGNORECASE, 'n') # [^\0-\177]
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	from /home/dmayorov/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/gems/css_parser-1.12.0/lib/css_parser/regexps.rb:11:in `new'

The fix is to upgrade css_parser to version 1.15.0 or higher: https://github.com/premailer/css_parser/blob/4fc5b070fb13f739eadbb27a4c5957f1713f12c6/CHANGELOG.md?plain=1#L27


/home/dmayorov/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/gems/compass-1.0.3/lib/compass/configuration/helpers.rb:89:in `block in detect_configuration_file': undefined method `exists?' for class File (NoMethodError)

        possible_files.detect{|f| File.exists?(f)}
                                      ^^^^^^^^
Did you mean?  exist?
	from /home/dmayorov/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/gems/compass-1.0.3/lib/compass/configuration/helpers.rb:89:in `each'

It's reported here but looks like it doesn't have a fix.
The reason is that File.exists? was removed in Ruby 3.2, now only File.exist? is available: https://www.ruby-lang.org/en/news/2022/12/25/ruby-3-2-0-released/

The workaround (althout ugly) I applied was

File.class_eval do
  class << self
    alias_method :exists?, :exist?
  end
end

/home/dmayorov/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/gems/pry-0.13.1/lib/pry/code.rb:342:in `<class:Code>': undefined method `=~' for class `Pry::Code' (NameError)
	from /home/dmayorov/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/gems/pry-0.13.1/lib/pry/code.rb:32:in `<class:Pry>'

Related issue: https://gitlab.com/gitlab-org/customers-gitlab-com/-/issues/6143

Solved by upgrading pry dependencies: bundle update pry-shell pry-byebug pry


Then finally the server started and the admin portal apparently was working, but on trying to load the dev portal:

NoMethodError (undefined method `tainted?' for an instance of String):
  
lib/developer_portal/lib/liquid/xss_protection.rb:15:in `render'

Related issues:
Shopify/liquid#1625
Shopify/liquid#1268

The solution is to upgrade liquid to 5.0.0. But it caused another issue:

/home/dmayorov/Projects/3scale/porta/lib/developer_portal/config/initializers/liquid.rb:5:in `<main>': can't modify frozen Hash: {nil=>nil, "nil"=>nil, "null"=>nil, ""=>nil, "true"=>true, "false"=>false, "blank"=>"", "empty"=>""} (FrozenError)
	from /home/dmayorov/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/gems/activesupport-6.1.7.8/lib/active_support/dependencies.rb:326:in `load'
	from /home/dmayorov/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/gems/activesupport-6.1.7.8/lib/active_support/dependencies.rb:326:in `block in load'

This is where I decided to stop 🙃 We'll upgrade in another step.

The issue was caused by `draper` gem upgrade (which was a result of
upgrading Ruby to v3). The issue was here:
https://github.com/drapergem/draper/blob/v4.0.2/lib/draper/automatic_delegation.rb#L10-L26

In decorators we delegate all methods to the decorated object. But this version of the library
only does that when there is no private method with the same name on the decorator.
In this case, as `admin_user`  was a private method on AccountDecorator, draper tried to call
`admin_user `on superclass, but it was not there, so it was failing with:
```
ActionView::Template::Error (super: no superclass method `admin_user' for #<AccountDecorator:0x00007f8784266d18
  @object=#<Account id: 11, org_name: "Testing" ...> Did you mean? admin_user_email):
```

Removing it from `private_methods` fixed the issue.
This test caused multiple tests fail with:
```
ThreadError: deadlock; lock already owned by another fiber belonging to the same thread
```

This is fixed in Rails 7.0.6 and higher: rails/rails#46553
```
DEPRECATION WARNING: Passing a path to `fixture_file_upload` relative to `fixture_path` is deprecated.
In Rails 7.0, the path needs to be relative to `file_fixture_path`.

Please modify the call from
`fixture_file_upload("wide.jpg")` to `fixture_file_upload("../../../test/fixtures/wide.jpg")`.
 (called from block (4 levels) in <main> at /home/dmayorov/Projects/3scale/porta/spec/acceptance/api/cms_file_spec.rb:24)
```
It used to be a default gem in Ruby 2.7, but since Ruby 3 it's not
default anymore
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.

1 participant