ArgumentError: Unable to generate hash without :hash_secret #450

Closed
zeroryu opened this Issue Apr 11, 2011 · 11 comments

Comments

Projects
None yet
7 participants

zeroryu commented Apr 11, 2011

i got that error after updating from 2.3.1.1 to the 2.3.11.

Any idea why this is happening? I assume there's no need to pass :hash_secret

Any chance you call #to_yaml on your model? I used a plugin that did this. #hash is then called on the attachment in:

/ree-1.8.7-2011.03/lib/ruby/1.8/yaml.rb:389:in `quick_emit'

Here the full backtrace:

ArgumentError: Unable to generate hash without :hash_secret
from (...)/gems/paperclip-2.3.11/lib/paperclip/attachment.rb:218:in `hash'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml.rb:389:in `quick_emit'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:38:in `to_yaml'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:18:in `node_export'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:18:in `add'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:18:in `to_yaml'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:17:in `each'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:17:in `to_yaml'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:16:in `map'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:16:in `to_yaml'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml.rb:391:in `call'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml.rb:391:in `emit'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml.rb:391:in `quick_emit'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:15:in `to_yaml'
>>> here the plugin called #to_yaml on my model <<<

OK, so I wanted to try out the new :hash(_secret) option.
I can now call #to_yaml on my new (unsaved) model without problems, but after a (failed) save attempt it crashes:

> u = User.new
> u.to_yaml # success
> u.save # => false (validations fail)
> u.to_yaml
TypeError: can't convert String into Integer
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml.rb:389:in `hash'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml.rb:389:in `quick_emit'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:38:in `to_yaml'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:18:in `node_export'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:18:in `add'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:18:in `to_yaml'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:17:in `each'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:17:in `to_yaml'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:16:in `map'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:16:in `to_yaml'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml.rb:391:in `call'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml.rb:391:in `emit'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml.rb:391:in `quick_emit'
from (...)/ree-1.8.7-2011.03/lib/ruby/1.8/yaml/rubytypes.rb:15:in `to_yaml'
from (irb):6

Some debugging revealed that at some point during #to_yaml ruby calls #hash on the following Hash:

{:image=>#<Paperclip::Attachment:0x106  [.....] @default_style=:original>}

Now, Paperclip::Attachment#hash returns a string while #to_yaml obviously expects an integer.

Maybe the cleanest solution would be to rename the hash interpolation?

I fixed this and requested a pull: #455

Contributor

sikachu commented Jun 20, 2011

I've rejected a patch on #455 because I don't think it's a way to go. Sorry guys, but let's find a way to preserve #hash while still can return Object#hash if YAML wants it.

sikachu closed this Jun 29, 2011

Contributor

sikachu commented Sep 23, 2011

Actually, there is a way to accomplish this. I've just committed e526c86 and it should be included in the next version.

raszi commented Oct 5, 2011

I still experiencing this issue with 2.4.2 and Rails 2.3.12.

I don't have permission to reopen this issue :(

raszi commented Oct 5, 2011

paperclip 2.3.8 is the latest working version

acuppy commented Oct 5, 2011

Same. Only version working for me is 2.3.8

kredmer commented Oct 19, 2011

same to me. 2.3.8 is the last working. I also tried with both patches. No chance.
(Ruby 1.8.7, Rails 2.3.11, S3 0.3.8 with s3_paperclip patch for s3 eu buckets)

@MSNexploder MSNexploder pushed a commit to MSNexploder/paperclip that referenced this issue Jan 15, 2012

@jyurek jyurek Fix the collision with Object#hash.
Closes #678. Closes #450.
3fd4c96

tibbon commented Apr 6, 2012

I'm still getting this in 3.0.0. Don't have permission to reopen, but its a problem.

tibbon commented Apr 6, 2012

has_attached_file :photo, :styles => { :large => "800x800>", :medium => "260x105>", :thumb => "130x70>" },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/aws.yml",
:path => ":id/:hash/:style.:extension"

@majofi majofi pushed a commit to majofi/paperclip that referenced this issue Jul 16, 2012

Mathias Fiedler monkeyfix for #450 not wokring to_yaml with paperclip 7a1eecc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment