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

model.remove_image! results in undefined method `read' for nil:NilClass #115

Closed
adamakhtar opened this issue Feb 25, 2013 · 6 comments
Closed
Labels

Comments

@adamakhtar
Copy link

Hello,

I've got carrierwave_backgrounder to successfully upload files directly to s3 using process_in_background and then let sidekik create versions in the background. Im on heroku but this error is happening in development on my mac.

However when I use remove_image!, the images on s3 are deleted, but on a subsequent call to save I see many errors in my sidekik console.

If I try removing carrierwave_backgrounder and fallback to processing in the main process all is fine. No errors.

My config is listed at the end. But here is what im doing in the console

r = WebRecipe.all[302]

r.remote_image_url = r.source_image 
=> "http://picky-palate.com/wp-content/uploads/2011/10/Fall-Chicken-Sausage-and-Butter-Bean-Stew-112sm.jpg"

r.save

2013-02-25T11:19:19Z 52802 TID-10oenzs CarrierWave::Workers::ProcessAsset JID-c9da033d437c0c4f7a94f908 INFO: start
2013-02-25T11:19:24Z 52802 TID-10oenzs CarrierWave::Workers::ProcessAsset JID-c9da033d437c0c4f7a94f908 INFO: done: 5.198 sec

r.image.url
=> "https://mybucket.s3.amazonaws.com/web_recipes/publisher_77/image/1030/6fc1f973-be8e-4f75-af79-89d846153976.jpg"

r.image.medium.url 
=> nil  #Strange. If the job has completed shouldn't there a be a url for my 'medium' version?

#maybe a reload will fix it
r.reload

r.image.medium.url 
=> nil #hmm don't understand this

r = WebRecipe.all[302] #grab record from db

r.image.medium.url
=> "https://mybucket.s3.amazonaws.com/web_recipes/publisher_77/image/1030/medium_54b50948-7e43-4353-93cc-dd96f3fe4254.jpg"

#hmm all is ok. Now for the main problem

r.remove_image!
=> ""

r.image.path
=> nil

r.save

2013-02-25T11:23:49Z 52802 TID-10oenzs CarrierWave::Workers::ProcessAsset JID-709e3067858205ad6b66874d INFO: start
2013-02-25T11:23:49Z 52802 TID-10oenzs CarrierWave::Workers::ProcessAsset JID-709e3067858205ad6b66874d INFO: fail: 0.004 sec
2013-02-25T11:23:49Z 52802 TID-10oenzs WARN: {"retry"=>true, "queue"=>"carrierwave", "class"=>"CarrierWave::Workers::ProcessAsset", "args"=>["WebRecipe", "1030", "image"], "jid"=>"709e3067858205ad6b66874d", "error_message"=>"undefined method `read' for nil:NilClass", "error_class"=>"NoMethodError", "failed_at"=>2013-02-25 11:23:49 UTC, "retry_count"=>0}
2013-02-25T11:23:49Z 52802 TID-10oenzs WARN: undefined method `read' for nil:NilClass
2013-02-25T11:23:49Z 52802 TID-10oenzs WARN: /Users/adam/.rvm/gems/ruby-1.9.3-p194-Ruby/gems/carrierwave-0.8.0/lib/carrierwave/uploader/cache.rb:77:in `sanitized_file'
/Users/adam/.rvm/gems/ruby-1.9.3-p194-Ruby/gems/carrierwave-0.8.0/lib/carrierwave/uploader/cache.rb:116:in `cache!'
/Users/adam/.rvm/gems/ruby-1.9.3-p194-Ruby/gems/carrierwave-0.8.0/lib/carrierwave/uploader/versions.rb:179:in `recreate_versions!'
/Users/adam/.rvm/gems/ruby-1.9.3-p194-Ruby/gems/carrierwave_backgrounder-0.2.0/lib/backgrounder/workers/process_asset.rb:16:in `perform'

The issue regarding other version urls not showing up may be totally unrelated but I thought id include it just in case.

Is this intended behaviour and im simply not reading the instructions (I've read and reread to no avail) or perhaps a bug?

Gem Versions
carrierwave_backgrounder 0.2.0
carrierwave 0.8.0
fog 1.3.1
ruby 1.9.3
rails 3.2.12

Config

#initializers/carrierwave_backgrounder.rb
CarrierWave::Backgrounder.configure do |c|
  c.backend :sidekiq, queue: :carrierwave
end
class WebRecipe < Active.....
  mount_uploader :image, ImageUploader
  process_in_background :image
  ...
end
#image_upoader
class ImageUploader < CarrierWave::Uploader::Base

  include CarrierWave::MiniMagick
  include ::CarrierWave::Backgrounder::Delay

  storage :fog

  def store_dir
    "web_recipes/publisher_#{model.publisher_id.to_s}/#{mounted_as}/#{model.id}"
  end

  process :resize_to_fit => [400, 10000]
  process :convert => 'jpg'

  version :thumb do
    process :resize_to_fill => [100, 100]
  end

  version :medium do 
    process :resize_to_fill => [270, 270]
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

  def filename
   "#{secure_token}.#{file.extension}" if original_filename.present?
  end

  protected
  def secure_token
    var = :"@#{mounted_as}_secure_token"
    model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.uuid)
  end
end
  CarrierWave.configure do |config|
    config.permissions = 0666
    config.storage = :fog
    config.fog_credentials = {
      :provider               => 'AWS',
      :aws_access_key_id      => ENV['AWS_ACCESS_KEY_ID'],
      :aws_secret_access_key  => ENV['AWS_SECRET_ACCESS_KEY']
    }
    config.fog_directory  = ENV['AWS_BUCKET'] 
  end
@lardawge
Copy link
Owner

I haven't had a chance to look at this but plan to in the next day or so. Been busy with work.

@adamakhtar
Copy link
Author

Thanks @lardawge - Ive recreated the error in a fresh rails install with identical gem versions. You can get the codebase here https://github.com/robodisco/cwb . Steps to recreate are listed in the readme as well as the small setup required (s3 keys)

Hope that helps

@lardawge
Copy link
Owner

That's awesome and very helpful. I will pull it down and let you know what I find.

@lardawge
Copy link
Owner

So it looks like CB is triggering a background job even if the attachment is empty. Looking into how to cover this... should have a fix shortly.

@adamakhtar
Copy link
Author

@lardawge that is absolutely awesome! Thanks for fixing that so fast.

@lardawge
Copy link
Owner

No problem. I'll release it in gem form in a couple of days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants