#1012 ✓resolved
siplux

dm-tags Model.tagged_with breaks: "undefined property or relationship 'tag_id' on Tagging'

Reported by siplux | August 18th, 2009 @ 03:07 PM | in 0.10.0

Simple fix, is to explicitly add

property :tag_id, Integer

to lib/tagging.rb

But the behavior of the bug is a little odd actually,

class Upload
property :id, Serial
tags_on :filter
end

In Irb

>> Upload.create(:filter_list => "foo, bar")
>> Upload.tagged_with "foo"
=> Upload @id=1

Now exit IRB (in my case merb -i) and go back into it

>> Upload.tagged_with "foo"

NoMethodError: undefined property or relationship 'tag_id' on Tagging
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query/path.rb:134:in `method_missing'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:1088:in `send'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:1088:in `append_string_condition'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:1088:in `each'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:1088:in `append_string_condition'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:1046:in `append_condition'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:664:in `initialize'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:664:in `each'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:664:in `initialize'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:354:in `update'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:370:in `merge'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/model.rb:700:in `scoped_query'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/model.rb:281:in `all'
        from /usr/lib/ruby/gems/1.8/gems/dm-tags-0.10.0/lib/dm-tags/dm_tags.rb:23:in `tagged_with'
        from (irb):1
        from :0

>> DataMapper.auto_upgrade!
>> Upload.tagged_with "foo"
#=> Upload @id=1

In case that isn't clear, for some reason dm-tags errors out initially, but calling "DM.auto_upgrade!" makes it work until you restart IRB, in which case it will cease to work until you 'upgrade' again

Another example

>> Upload.all "taggings.tag_id" => 1
#=> NoMethodError: undefined property or relationship 'tag_id' on Tagging
Upload.all "taggings.taggable_id" => 1
#=> Upload @id=1

Comments and changes to this ticket

  • siplux

    siplux August 18th, 2009 @ 03:28 PM

    Attached diff (not that it was really necessary)

  • siplux

    siplux August 18th, 2009 @ 03:29 PM

    • Title changed from “dm-tags is broken, "undefined property or relationship 'tag_id' on Tagging'” to “dm-tags Model.tagged_with breaks: "undefined property or relationship 'tag_id' on Tagging'”
  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) August 18th, 2009 @ 07:56 PM

    • State changed from “new” to “unconfirmed”
    • Milestone set to 0.10.0

    siplux,

    From the stacktrace i can see that you're using 0.10. Do you use latest next branches or some older version? In case you don't use latest next branches, could you test that out too?

    Also, merb_datamapper uses the following snippet to make sure all properties are defined before accessing them.

    DataMapper::Model.descendants.each do |model|
      model.relationships.each_value { |r| r.child_key }
    end
    

    Do you use merb_datamapper? I assume you do since you mentioned merb -i. Also, wycats/merb is not fully compatible with dm-0.10. You might want to try out my fork of merb at http://github.com/snusnu/merb for 0.10 compatibility. Unfortunately, my fork currently is only based on merb edge (no 1.0.12 compatible version). You can find the 0.10 compatible version in the dm-0.10.0 branch of my merb fork.

    If you're not already using that, you might want to try and see if your problem still occurs when using my fork

  • siplux

    siplux August 19th, 2009 @ 01:21 PM

    Martin, I'm using the latest next branch, I pull daily from the repo. That was the latest pull from yesterday, I haven't tried today yet though.

    Like a deranged surgeon with only one year of med school and a knife full of dreams - I was using a combination of your fork and the official branch...basically I just commented out the line 55 area of merb_datamapper/lib/merb_datamapper.rb without introducing the other changes that your fork had:

    def self.run

    # Merb.logger.verbose! 'Merb::Orms::DataMapper::Associations block' ...

    end

    Now I feel like an ass ... I bet that's part of, if not, the problem.

  • siplux

    siplux August 19th, 2009 @ 01:41 PM

    Err...the h1 tags are commented out lines

  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) August 19th, 2009 @ 04:50 PM

    Hehe siplux, no worries :) If you can confirm that your original problem is no more, that would be awesome and we could close the ticket :)

  • siplux

    siplux August 20th, 2009 @ 12:05 AM

    I just tested it with your fork. It took me about 5 minutes of raking this and that until all the dependencies were built, but problem is fixed with it as far as I can tell.

    So that I'm not crying wolf in the future, is your fork the preferred choice for discerning gentlemen?

  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) August 20th, 2009 @ 12:25 AM

    • State changed from “unconfirmed” to “resolved”

    Awesome, so we can mark this resolved. Regarding my merb fork, I heard of some people using it already and afaik there is no real other alternative. I also talked to the maintainer of merb_datamapper and he said he'll push it to wycats/master once dm 0.10.0 is ready and merb people figured out their release plan.

  • Tim Uruski

    Tim Uruski March 1st, 2010 @ 09:03 PM

    I was just bitten by this bug while using DataMapper 0.10.2 with dm-tags 0.10.2, do_postgres 0.10.1 and Sinatra 0.9.4.

    I tried to replicate using do_sqlite3 (for illustration purposes) but couldn't trigger it, so I think the bug is related to PostgreSQL. To trigger the bug I created a simple model with tags and started building a simple REST API. When it came time to fetch instances by tag, I got the above listed error only after my app had just restarted. Once a request by ID was performed (or create, update or destroy) had been run the tags worked fine.

    Here's some rough pseudo-code:

      require 'sinatra'
      require 'dm-core'
      require 'dm-tags'
      
      class Model
        include DataMapper::Resource
        property :id, Serial
        has_tags
      end
      
      DataMapper.setup(:default, 'postgres://localhost/foo')
      # DataMapper.auto_migrate! # Remove before restart
      
      post '/models/create' do
        m = Model.new
        m.tag_list = params[:tags]
        m.save
      end
      
      post '/models/fetch-by-id/:id' do
        Model.get(params[:id])
      end
      
      post '/models/fetch-by-tag/:tag' do
        Model.tagged_with(params[:tag])
      end
    

    A quick fix that I found was to make a new instance of the model with tags in my app startup code, no need to save it. It seems like some sort of initialization code isn't being called otherwise.

      # This makes tags work after app restart
      Model.new
    

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 »

Attachments

Pages