error from mm 0.13.0 NoMethodError: undefined method `>=' for []:Array

33 views
Skip to first unread message

bethany soule

unread,
Jun 17, 2014, 6:24:41 PM6/17/14
to mongo...@googlegroups.com
I just upgraded from mm 0.9.0 to 0.13.0 and I'm occasionally getting that error in some background jobs I'm running. I'm not really sure how to dig in and debug this further at this point. We're running ruby 1.9.3, MongoMapper 0.13.0, mongo v 2.4.5. 

The error message is:
    NoMethodError: undefined method `>=' for []:Array

Here's a stack trace: 
    /var/www/beem/releases/20140616185315/app/models/goal.rb:1495:in `on_good_side?'
    /var/www/beem/releases/20140616185315/app/models/goal.rb:1502:in `retroratchetable?'
    /var/www/beem/releases/20140616185315/app/performers/graph_job.rb:66:in `perform'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/resque-1.19.0/lib/resque/job.rb:127:in `perform'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/resque-1.19.0/lib/resque/worker.rb:163:in `perform'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/resque-1.19.0/lib/resque/worker.rb:130:in `block in work'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/resque-1.19.0/lib/resque/worker.rb:116:in `loop'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/resque-1.19.0/lib/resque/worker.rb:116:in `work'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/resque-1.19.0/lib/resque/tasks.rb:27:in `block (2 levels) in <top (required)>'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
    /usr/local/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
    /var/www/beem/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
    /var/www/beem/shared/bundle/ruby/1.9.1/bin/rake:23:in `load'
    /var/www/beem/shared/bundle/ruby/1.9.1/bin/rake:23:in `<main>'

so, the error is definitely getting thrown in my code. Here's what that 'on_good_side?' method is doing though:

    def on_good_side? 
      self.bb[:lane] * self.yaw >= 0
    end

where self.bb is a Hash and self.yaw is an Integer. So if this were about bad data (e.g. either the :lane key not existing in bb or yaw being nil) , I'd expect it to be a nil object error, like:

    NoMethodError: You have a nil object when you didn't expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.*

But I'm getting this error about >= on []:Array.... It would seem that self.bb[:lane] is an empty array -- not an empty hash or a nil hash value. Which is funny.

It seems likely that it's some subtle problem in MongoMapper since it showed up right after the upgrade, and since it seems to have something to do with the document not getting instantiated in memory correctly? I'm not sure where to go next with debugging this at this point though!

Thanks for the help!
Bethany

Chris Heald

unread,
Jun 17, 2014, 6:32:26 PM6/17/14
to mongo...@googlegroups.com
Have you looked at the raw data in the DB to see what's in there? MM 0.13.0 does (much) less coercion of bad data, and trusts that the data you declare is the data your DB is providing.

From an IRB console, try `Goal.collection.find_one({_id: BSON::ObjectId("5397644124ac61d3fcb0ac8d")})` replacing the ID with your document's ID. That will get you the raw data. Specifically, inspect the value of `bb.lane` and see if it is indeed a scalar value - I suspect you've ended up with an array in there somehow.

Bethany M. Soule

unread,
Jun 17, 2014, 7:24:46 PM6/17/14
to mongo...@googlegroups.com
Thanks for the tip, Chris! The documents I've seen the error on so far
have come up clean when I inspect them. I'm going to run an offline
query through all my data to see if I can turn up any bad documents.

Bethany
> --
> You received this message because you are subscribed to the Google
> Groups "MongoMapper" group.
> For more options, visit this group at
> http://groups.google.com/group/mongomapper?hl=en?hl=en
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "MongoMapper" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/mongomapper/Id4LVrSBQ5U/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> mongomapper...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
http://bethaknee.com
http://beeminder.com -- Reminders with a sting

Jon Kern

unread,
Jun 20, 2014, 9:15:18 PM6/20/14
to mongo...@googlegroups.com
BTW: this is a good tip in general… If things suddenly crap out on a view that used to work, for example, it is not uncommon for it to be data related — especially in the early days of getting something running and adding new methods or new validations to old data…

Also, looking at your code:
    def on_good_side? 
      self.bb[:lane] * self.yaw >= 0
    end

I think of some things to ask:
  1. Do you have validations that require these values to be present and numeric? Or do you allow nils or 0s?
  2. Do you have a handful of rspecs that prove how this method should behave in the presence of expected values?
  3. I would add parentheses because I am too lazy to care about operator precedence (self.bb[:lane] * self.yaw) >= 0

You received this message because you are subscribed to the Google Groups "MongoMapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongomapper...@googlegroups.com.

Bethany M. Soule

unread,
Jun 25, 2014, 4:21:51 PM6/25/14
to mongo...@googlegroups.com
Thanks y'all! So I checked my data, and confirmed that -- at least for
bb[:lane] and yaw -- t'was good. Weirdly this pull request
https://github.com/mongomapper/mongomapper/pull/579 that Chris merged
in yesterday (Thanks!) seems to have resolved the majority of these
exceptions even though I was debugging an entirely different issue.
I'm still getting a few "undefined method for []:Array" errors but
from different parts of my code, so I've still got a Mystery on my
hands :-)

I guess next up: determining precisely how the two are related.

Bethany
Reply all
Reply to author
Forward
0 new messages