#677 ✓resolved
Paul Dlug

Error when using UUID as primary key

Reported by Paul Dlug | November 28th, 2008 @ 07:42 PM

Using the UUID type from dm-types as a primary key throws an exception (below). The UUID type in general seems to work just fine when :key is not set.

I am defining the key as:

property :id, ::DataMapper::Types::UUID, :key => true, :unique_index => true, :default => lambda { ::UUID.random_create }

This was tested using 0.9.7 as well as the latest install from dkubb's fork of dm-core. Attached is the full script that can be used to replicate the problem.

/Library/Ruby/Gems/1.8/gems/dm-core-0.9.8/lib/dm-core/resource.rb:619:in hash': bignum too big to convert intolong' (RangeError)

from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.8/lib/dm-core/resource.rb:619:in `[]='
from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.8/lib/dm-core/resource.rb:619:in `hookable__create_nan_before_advised'
from /Library/Ruby/Gems/1.8/gems/extlib-0.9.9/lib/extlib/hook.rb:294:in `create'
from /Library/Ruby/Gems/1.8/gems/extlib-0.9.9/lib/extlib/hook.rb:292:in `catch'
from /Library/Ruby/Gems/1.8/gems/extlib-0.9.9/lib/extlib/hook.rb:292:in `create'
from /Library/Ruby/Gems/1.8/gems/dm-core-0.9.8/lib/dm-core/resource.rb:547:in `hookable__save_nan_before_advised'
from /Library/Ruby/Gems/1.8/gems/extlib-0.9.9/lib/extlib/hook.rb:294:in `save'
from /Library/Ruby/Gems/1.8/gems/extlib-0.9.9/lib/extlib/hook.rb:292:in `catch'
from /Library/Ruby/Gems/1.8/gems/extlib-0.9.9/lib/extlib/hook.rb:292:in `save'
from uuidtest.rb:19

Comments and changes to this ticket

  • Paul Dlug

    Paul Dlug December 1st, 2008 @ 07:57 PM

    I have tracked this down to a problem in uuidtools itself, in a simple script the following will generate the error:

    u = UUID.random_create puts u.hash puts [u].hash

    This appears to be due to the UUID object generating a very large value for hash which overflows the maximum value of Fixnum when Array and similar collection objects calculate a hash based on the hash value of their members. I sent a note to the maintainer of uuidtools and will see if a patch can be worked out.

  • Paul Dlug

    Paul Dlug December 1st, 2008 @ 11:35 PM

    Thanks to a quick fix and new gem release of uuidtools by Bob Aman (sporkmonger) this bug may be resolved by requiring uuidtools ~>1.0.6 in dm-types.


  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) December 1st, 2008 @ 11:49 PM

    • State changed from “new” to “resolved”
    • Assigned user set to “Dan Kubb (dkubb)”

    Paul, I have resolved this with the following commit:


Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »