Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

ArgumentError: Unable to generate hash without :hash_secret #450

Closed
zeroryu opened this Issue · 11 comments

7 participants

@zeroryu

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

@jeanmartin

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 <<<
@jeanmartin

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?

@jeanmartin

I fixed this and requested a pull: #455

@sikachu
Owner

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 sikachu closed this
@sikachu
Owner

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

@raszi

I still experiencing this issue with 2.4.2 and Rails 2.3.12.

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

@raszi

paperclip 2.3.8 is the latest working version

@acuppy

Same. Only version working for me is 2.3.8

@kredmer

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 referenced this issue from a commit in MSNexploder/paperclip
@jyurek jyurek Fix the collision with Object#hash.
Closes #678. Closes #450.
3fd4c96
@adamtait adamtait referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@tibbon

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

@tibbon

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 referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@majofi majofi referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@majofi majofi referenced this issue from a commit in majofi/paperclip
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
Something went wrong with that request. Please try again.