#1083 ✓resolved

specify :fields causes problem with lazy loading

Reported by BrianTheCoder | October 7th, 2009 @ 04:49 PM | in 0.10.2

Comments and changes to this ticket

  • BrianTheCoder

    BrianTheCoder October 7th, 2009 @ 05:15 PM

    • Tag set to 0.10.0, fields, relationships

    m.tagged_users.all(:user => nil, :fields => [:user_name]).map(&:user_name) TypeError: can't modify frozen object

    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/resource.rb:491:in `original_attributes'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/resource.rb:90:in `key'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/resource.rb:89:in `map'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/resource.rb:89:in `key'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/collection.rb:1208:in `resource_added'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/associations/one_to_many.rb:314:in `resource_added'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/collection.rb:1228:in `resources_added'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/collection.rb:1228:in `each'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/collection.rb:1228:in `resources_added'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/collection.rb:480:in `concat'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/collection.rb:1008:in `lazy_load'
    from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/associations/one_to_many.rb:288:in `lazy_load'
    from /usr/lib/ruby/gems/1.8/gems/extlib-0.9.14/lib/extlib/lazy_array.rb:451:in `map'
    from (irb):4

    m.tagged_users.all(:user => nil).map(&:user_name) => ["Florence Mottay", "Fabian Casteran"]

    That's pretty much it. m is a resource that has this assocation, basically polymorphic.

    has n, :tagged_users, :child_key => [ :object_id ], :object_type => self.to_s.underscore

    class TaggedUser
    include DataMapper::Resource

    property :id, Serial property :user_id, Integer, :index => true property :user_name, String, :length => 150, :nullable => false property :object_type, String, :index => true, :nullable => false property :object_id, Integer, :index => true, :nullable => false end

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) October 8th, 2009 @ 12:52 AM

    • Milestone set to 0.10.2
    • Tag changed from 0.10.0, fields, relationships to fields, relationships
    • State changed from “new” to “accepted”
    • Assigned user set to “Dan Kubb (dkubb)”

    This is happening because the resource is being loaded without a key, which marks it as read-only, since you can't persist a Resource without a key. To make sure that it's clear the resource is read-only, I freeze it.

    In this case, a method is being accessed that memoizes a Hash on first-access in an @ivar. If the object is frozen, the @ivar cannot be assigned to, causing the explosion.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) October 23rd, 2009 @ 02:05 AM

    • State changed from “accepted” to “resolved”

    This should now be resolved in edge dm-core. Marking this as resolved, but if this is not fixed for you please add a comment with a stand-alone script that reproduces the problem.

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 »

People watching this ticket