Massive Flaw in DataMapper 0.9.6 - Write Once Read Many Many Many Many Many, Im outta space here…

So I found a pretty massive flaw in DataMapper (ticket @ lighthouse).  Whenever using the :fields attribute when doing Resource#first or Resource#all a crap load (techincally speaking) of queries are fired at MySQL.  I put a ticket in and a lot of information and links to some pasties with examples (see lighthouse).  I don’t have the time to look into this now, being that I have a deadline Saturday, but it’s a pretty serious problem and I’m sure a lot of people are experiencing it and don’t realize it.

To try it out for yourself lets use Merb (and Ive tried it without merb, and without any dm plugins and the problem still persists).

Steps to reproduce:


merb-gen app my_test_app

cd ./my_test_app

merb -i

DataMapper.auto_migrate!

#turn on dm loggering (thats what I call it)

DataObjects::Mysql.logger = DataObjects::Logger.new('log/dm.log', 0)

# create a few users, then, get their IDs, I dare you...

User.all(:fields=>[:id])

So, the problem is if you look at your mysql log or DataMapper Query Log you’ll see a crapload of selects trying to get what the first select in the list retrieved.  The funnier part is, the subsequent selects are selecting the fields that aren’t included in the :fields list.

Why is this a huge problem?  That query above for my 3 user test table generated about 90 trips to MySQL.  The ‘friend button’ on Vokle.com just generated about 240 trips to MySQL in one click, that’s how I found the issue in the first place.

Someone fix this please!?  If its not fixed by Saturday (my day ‘off’), I’m going to look into it.

Happy (bug) hunting.

Tags: ,

5 Responses to “Massive Flaw in DataMapper 0.9.6 - Write Once Read Many Many Many Many Many, Im outta space here…”

  1. Bernerd Schaefer Says:

    Cory, I’ve updated the ticket with some more information.

    http://wm.lighthouseapp.com/projects/4819-datamapper/tickets/626-using-fields-causes-datamapper-to-generate-tons-of-queries-in-mysql

    For anyone else interested, it turns out this is a much more localized problem than it may have appeared. In IRB, your objects have inspect called on them, which then makes DataMapper try to load any missing attributes. This works great for properties which are declared as :lazy, but the use case for unloaded attributes that aren’t lazy (i.e, asking for the name of a user loaded with :fields => [:id]) hadn’t been encountered.

    All told, it should be an easy fix for anyone who’s got the time.

  2. Cory O'Daniel Says:

    Cool, its nice to see some light shed on this from somebody that knows the internals of DM

  3. Cory O'Daniel Says:

    Magic spells. I just woke up from my night of Halloween debauchery (and it was pretty debaucherous) and this bug is fixed. Mr. Schaefer is what some people would refer to as ‘the man’. Thanks for being on top of this!

  4. Vokle > DataMapper is Viewable Says:

    [...] when I’m panicking I’m a fan of datamapper.  I like how clean it generally makes my code, but I do notice that [...]

  5. Nola Kuntzman Says:

    Lovely sharp publish. By no means thought that it was this effortless. Extolment to you!

Leave a Reply