instructure / canvas-lms

The open LMS by Instructure, Inc.
https://github.com/instructure/canvas-lms/wiki
GNU Affero General Public License v3.0
5.41k stars 2.42k forks source link

ArgumentError: comparison of Gem::Version with String failed #2322

Closed amg-web closed 4 months ago

amg-web commented 4 months ago

On latest prod origin/stable/2024-02-14

I have another deployment issue Ubuntu 22.04, ruby 3.1

canvas@learn:~/public_html$ RAILS_ENV=production bundle exec rake db:initial_setup
rake aborted!
ArgumentError: comparison of Gem::Version with String failed
/home/canvas/public_html/gems/canvas_cache/lib/canvas_cache/redis_cache_store.rb:30:in `<'
/home/canvas/public_html/gems/canvas_cache/lib/canvas_cache/redis_cache_store.rb:30:in `<module:ClassMethods>'
/home/canvas/public_html/gems/canvas_cache/lib/canvas_cache/redis_cache_store.rb:26:in `<module:RedisCacheStore>'
/home/canvas/public_html/gems/canvas_cache/lib/canvas_cache/redis_cache_store.rb:25:in `<module:CanvasCache>'
/home/canvas/public_html/gems/canvas_cache/lib/canvas_cache/redis_cache_store.rb:24:in `<top (required)>'
/home/canvas/public_html/gems/canvas_cache/lib/canvas_cache.rb:21:in `require_relative'
/home/canvas/public_html/gems/canvas_cache/lib/canvas_cache.rb:21:in `<top (required)>'
/home/canvas/public_html/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
/home/canvas/public_html/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
/home/canvas/public_html/vendor/bundle/ruby/3.1.0/gems/bundler-2.5.3/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
/home/canvas/public_html/vendor/bundle/ruby/3.1.0/gems/bundler-2.5.3/lib/bundler/runtime.rb:55:in `each'
/home/canvas/public_html/vendor/bundle/ruby/3.1.0/gems/bundler-2.5.3/lib/bundler/runtime.rb:55:in `block in require'
/home/canvas/public_html/vendor/bundle/ruby/3.1.0/gems/bundler-2.5.3/lib/bundler/runtime.rb:44:in `each'
/home/canvas/public_html/vendor/bundle/ruby/3.1.0/gems/bundler-2.5.3/lib/bundler/runtime.rb:44:in `require'
/home/canvas/public_html/vendor/bundle/ruby/3.1.0/gems/bundler-2.5.3/lib/bundler.rb:187:in `require'
/home/canvas/public_html/config/application.rb:28:in `<top (required)>'
/home/canvas/public_html/Rakefile:6:in `require'
/home/canvas/public_html/Rakefile:6:in `<top (required)>'
/home/canvas/public_html/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)
Maclenn77 commented 4 months ago

Hi, @amg-web . How is your config/cache_store.yml file ? Did you copy cache_store.yml.example to cache_store.yml?

amg-web commented 4 months ago

@Maclenn77 sure:

production:
    cache_store: redis_cache_store

Last working for me is version "origin/stable/2024-01-31" with later versions I have this https://github.com/instructure/canvas-lms/issues/2316 and "ArgumentError: comparison of Gem::Version with String failed"

Maclenn77 commented 4 months ago

@amg-web The error raises in this line of code:

gems/canvas_cache/lib/canvas_cache/redis_cache_store.rb

 ln 30     unless ActiveSupport.version < "7.1"

Last working version for you is very different:

require "active_support/cache"

module CanvasCache
  module RedisCacheStore
    module ClassMethods
      ActiveSupport::Cache::RedisCacheStore.singleton_class.prepend(self)

      def build_redis(**redis_options)
        Redis.patch
        return ::Redis::Cluster.new(**redis_options) if redis_options.key?(:nodes)

        super
      end
    end
  end
end

Update: This won't work: As a workaround, I would try to change "7.1" which is a string to a floating number to allow comparisons, such as "7.1".to_f.

Gem::Version compares between Gem::Versions, to convert the string to Gem::Version, add Gem::Version.new("7.1")

Maclenn77 commented 4 months ago

Hey, @amg-web , check last master file: gems/canvas_cache/lib/canvas_cache/redis_cache_store.rb

You can notice that they already fix that issue using Gem::Version.new("7.1"), as I suggested.

amg-web commented 4 months ago

@Maclenn77 Thanks Hope they fix it soon in prod :)

I wonder if is the gem pact-mock_service issue on my deployment only?

amg-web commented 4 months ago

Hey, @amg-web , check last master file: gems/canvas_cache/lib/canvas_cache/redis_cache_store.rb

ou, this is not the only place of such error. I think I'll wait until fixed

Maclenn77 commented 4 months ago

Hey, @amg-web . pact-mock_service seems like a test library, I wonder why it's messing up with your prod installation, usually, test libraries are not installed in prod versions. You could try to run the initial setup flagging that it's for the production environment with RAILS_ENV=production at the beginning of the command.

About the #2316 issue, as far as I can see it's not related to this one. You can create your own branch and commit your changes there with the fixes, your fix for pact-mock_service, and a change on the ln 30 of this file.

gems/canvas_cache/lib/canvas_cache/redis_cache_store.rb:30

It would be something like:

git checkout -b  your-new-branch

Then make your changes, in the redis_cache_store.rb file, it would be:

#  Previous version:
#     unless ActiveSupport.version < "7.1"
# Your version:
 unless ActiveSupport.version < Gem::Version.new("7.1")

Save and commit

git add . && git commit -m "A descriptive message about your change"

When you need to upgrade to prod, you can check out back to prod and pull.

git checkout prod && git pull 

Your changes won't be kept here, if you still need them, you can check out your branch and rebase prod.

git checkout your-branch && git rebase origin/prod

If there's some merge conflict, you'll need to manually fix them, but the changes that you would perform are small, so it shouldn't be a big issue.

Hey, @amg-web , check last master file: gems/canvas_cache/lib/canvas_cache/redis_cache_store.rb

ou, this is not the only place of such error. I think I'll wait until fixed

amg-web commented 4 months ago

@Maclenn77

Hey, @amg-web . pact-mock_service seems like a test library, I wonder why it's messing up with your prod installation, usually, test libraries are not installed in prod versions. You could try to run the initial setup flagging that it's for the production environment with RAILS_ENV=production at the beginning of the command.

RAILS_ENV=production does not have influence on bundle install

but I use bundle config set --local without test

and this make problem. when I remove this config bundle install works without issues.

I already located the responsible pull request and posted it in the respective ticket.

And thanks for git manual. at least 1 place in the code with same problem, I did not dig it further. I'll wait when updated code goes to prod.

amg-web commented 4 months ago

Looks fixed