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

Gem::LoadError on azure-storage-blob (AzureStorage adapter) in Rails 7 #44960

Closed
equivalent opened this issue Apr 26, 2022 · 4 comments
Closed

Comments

@equivalent
Copy link
Contributor

equivalent commented Apr 26, 2022

Steps to reproduce

I've upgraded my Ruby form 2.7.4 to 3.1.1 & Rails from 6.1 to 7.0.2.3

in my Gemfile I have:

gem "rails", "~> 7.0.0"
# ...
gem 'mini_magick', '~> 4.8'               # not important
gem "image_processing", "~> 1.2"          # not importnat
gem "azure-storage-blob", require: false  #important
gem 'active_storage_validations'        # https://github.com/igorkasyanchuk/active_storage_validations not imporrtant
gem 'aws-sdk-s3', require: false   
# ...

running code from https://github.com/rails/rails/blob/main/activestorage/lib/active_storage/service/configurator.rb#L30 in rails console :

 bin/rails c
Loading development environment (Rails 7.0.2.3)
3.1.1 :001 > class_name = "AzureStorage"
 => "AzureStorage" 
3.1.1 :002 > require "active_storage/service/#{class_name.to_s.underscore}_service"
/Users/t/.rvm/gems/ruby-3.1.1@pobble-api/gems/bundler-2.3.12/lib/bundler/rubygems_integration.rb:291:in `block (2 levels) in replace_gem': can't activate azure-storage-blob (>= 2.0), already activated azure-storage-blob-1.1.0. Make sure all dependencies are added to Gemfile. (Gem::LoadError)
3.1.1 :003 > class_name = "S3"
 => "S3" 
3.1.1 :004 > require "active_storage/service/#{class_name.to_s.underscore}_service"
 => true 

Reason

in https://github.com/rails/rails/blob/main/activestorage/lib/active_storage/service/azure_storage_service.rb:3

there is a line:

gem "azure-storage-blob", ">= 2.0"
# in bin/rails c in Ruby 3.1.1 && Rails 7.0.2.3
 :001 > gem "azure-storage-blob", ">= 2.0"
/Users/t/.rvm/gems/ruby-3.1.1@pobble-apix/gems/bundler-2.2.27/lib/bundler/rubygems_integration.rb:336:in `block (2 levels) in replace_gem': can't activate azure-storage-blob (>= 2.0), already activated azure-storage-blob-1.1.0. Make sure all dependencies are added to Gemfile. (Gem::LoadError)

I'm suspecting that there's something in Rails 7 causing this not to load properly .

one more note:

In my app I use AWS S3 (primary) mirrored to Azure(seconday) If I disable AzureStorage and only use S3 adapter it's fine, but with Azure storage setup fails. Therefore S3 adapter is not affected by this and this line is working in s3 adapter

# in bin/rails c in Ruby 3.1.1 && Rails 7.0.2.3
gem "aws-sdk-s3", "~> 1.48"
 => true 

Seems like something how azure_storage_blob is being loaded in Ruby 3.1 / Rails 7.0.2.3 because same version of azure_storage_blob in Ruby2.7.4/RoR 6.1 worked (comment bellow)

System configuration

Rails version: 7.0.2.3

Ruby version: 3.1.1

bundler version: 2.3.12

azure-storage-blob version: (1.1.0)

# config/storage.yml

amazon_production:
  service: S3
  access_key_id: xxxxx
  secret_access_key: xxxxx
  region: eu-west-2
  bucket: xxxxx

azure_production:
 service: AzureStorage
 storage_account_name:  xxxxxx
 storage_access_key: xxxxx
 container: xxxxx

aws_production_mirrored_to_azure:
  service: Mirror
  primary: amazon_production
  mirrors: [ azure_production ]

@equivalent
Copy link
Contributor Author

equivalent commented Apr 26, 2022

I've tried to load the same setup in various setups:

RoR 6.1 & Ruby 2.7.4

rails c
2.7.4 :002 > class_name = "AzureStorage"
 => "AzureStorage" 
2.7.4 :003 > require "active_storage/service/#{class_name.to_s.underscore}_service"
 => true

bundler -v
Bundler version 2.3.12 

RoR 7.0.2.3 & Ruby 2.7.4

 class_name = "AzureStorage"
 => "AzureStorage" 
2.7.4 :006 > require "active_storage/service/#{class_name.to_s.underscore}_service"
Traceback (most recent call last):
/Users/t/.rvm/gems/ruby-2.7.4@pobble-apiiii/gems/bundler-2.3.12/lib/bundler/rubygems_integration.rb:291:in `block (2 levels) in replace_gem': can't activate azure-storage-blob (>= 2.0), already activated azure-storage-blob-1.1.0. Make sure all dependencies are added to Gemfile. (Gem::LoadError)

bundler -v 
Bundler version 2.3.12
ruby -v
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [arm64-darwin21]
rails -v
Rails 7.0.2.3

RoR 6.1 & Ruby 3.1.1

 :002 > class_name = "AzureStorage"
 => "AzureStorage" 
 :003 > require "active_storage/service/#{class_name.to_s.underscore}_service"
 => true 


ruby -v
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [arm64-darwin21]

rails -v
Rails 6.1.4.1

bundler -v
Bundler version 2.2.27

gem --version
3.3.7

RoR 7.0.2.3 & Ruby 3.1.1

I've started again and upgraded Rails from scratch one more time in the project (so same as original description but done one more time)

Loading development environment (Rails 7.0.2.3)
 :001 > class_name = "AzureStorage"
 => "AzureStorage" 
 :002 > require "active_storage/service/#{class_name.to_s.underscore}_service"
/Users/t/.rvm/gems/ruby-3.1.1@pobble-apix/gems/bundler-2.2.27/lib/bundler/rubygems_integration.rb:336:in `block (2 levels) in replace_gem': can't activate azure-storage-blob (>= 2.0), already activated azure-storage-blob-1.1.0. Make sure all dependencies are added to Gemfile. (Gem::LoadError)



ruby -v
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [arm64-darwin21]

rails -v
Rails 7.0.2.3

bundler -v
Bundler version 2.2.27

gem -v
3.3.7

Conclusion at this point

it seems there is something in Rails 7.0.2.3 that is causing this

@equivalent equivalent changed the title AzureStorage crush after Ruby & Rails upgrade Gem::LoadError on azure-storage-blob (AzureStorage adapter) after Rails upgrade Apr 26, 2022
@equivalent equivalent changed the title Gem::LoadError on azure-storage-blob (AzureStorage adapter) after Rails upgrade Gem::LoadError on azure-storage-blob (AzureStorage adapter) in Rails 7 Apr 26, 2022
@skipkayhil
Copy link
Member

This looks like expected behavior to me. The requirement in active_storage_service was updated in 0920b02 because version 1.1.0 of the gem doesn't support Ruby > 2.5

To fix this you should upgrade your azure-storage-blob in Gemfile to be >= 2.0 as well

@equivalent
Copy link
Contributor Author

equivalent commented Apr 26, 2022

@skipkayhil you deserve a cookie !!

yes you right as soon as I've updated my Gemfile to

gem 'azure-storage-blob', "~> 2.0", require: false

...it started to work.

Now I see it's obvious gem "azure-storage-blob", ">= 2.0" I'm stupid not to realize this when reading https://github.com/rails/rails/blob/main/activestorage/lib/active_storage/service/azure_storage_service.rb:3

Maybe it's worth mentioning this in official ActiveStorage guide https://edgeguides.rubyonrails.org/active_storage_overview.html So I've created PR #44965

Screenshot 2022-04-26 at 21 01 24

Thank you, you saved my day!

@equivalent
Copy link
Contributor Author

this is not a bug, upgrade gem 'azure-storage-blob to >= 2.0 and all good

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

No branches or pull requests

2 participants