10

I'm getting this error on a Rails app on Heroku:

NameError: uninitialized constant ActiveStorage::Analyzer::ImageAnalyzer::MiniMagick
/app/vendor/bundle/ruby/3.0.0/gems/activestorage-6.1.3/lib/active_storage/analyzer/image_analyzer.rb:46:in `rescue in read_image'

It's happening in Sidekiq jobs generated from ActiveStorage::AnalyzeJob and seems to trigger whenever I try to upload an image to my AWS storage (the images are not reaching my bucket).

What is odd is I have a duplicate staging version of the app on Heroku that uses the same config and it does not trigger these errors (the images do reach my bucket from staging).

Both versions of the app are using the same gems and buildpacks.
Both versions have ImageMagick 6.9.10-23 and mini_magick 4.11.0 installed.
And both versions show the same error at the console if I reference the class mentioned, e.g.:

$ heroku run rails c -a my-staging-app
Running rails c on ⬢ my-staging-app... up, run.9122 (Free)
Loading staging environment (Rails 6.1.3)
irb(main):001:0*  ActiveStorage::Analyzer::ImageAnalyzer
=> ActiveStorage::Analyzer::ImageAnalyzer
irb(main):002:0>  ActiveStorage::Analyzer::ImageAnalyzer::MiniMagick
Traceback (most recent call last):
        1: from (irb):2:in `<main>'
NameError (uninitialized constant ActiveStorage::Analyzer::ImageAnalyzer::MiniMagick)
Did you mean?  MiniMime

But I have no idea why the staging app doesn't hit the error when uploading to AWS.

Does anyone know how I can fix the uninitialized constant? (Where does the referenced class need to come from?)

Karl Bishop
  • 391
  • 1
  • 14
  • Did you ever figure this out? – Randy Burgess Nov 19 '21 at 05:07
  • Kind of - I don't know why I was getting this error but I realised my config was actually not identical between staging and production - I still had config.active_storage.service = :local in production.rb. I changed it to config.active_storage.service = :amazon and now files are uploaded to my AWS bucket without any errors. – Karl Bishop Nov 23 '21 at 04:48
  • @KarlBishop Maybe change your comment to an answer and accept it – kwerle Jul 05 '23 at 00:29
  • @kwerle Yeah, I guess that makes it more visible/helpful - have done – Karl Bishop Jul 10 '23 at 23:59

1 Answers1

1

I don't know why I was getting this particular error but I realised my config was actually not identical between staging and production.

I still had config.active_storage.service = :local in production.rb.

I changed it to config.active_storage.service = :amazon and now files are uploaded to my AWS bucket without any errors.

Karl Bishop
  • 391
  • 1
  • 14