Search code examples
ruby-on-railsactiverecordrubinius

NoMethodError using order intermittently


I am getting the following error in a production rails application intermittently

NoMethodError (undefined method `values' on priority:Symbol.):
  app/controllers/things_controller.rb:33:in `index'

The offending line looks like this:

@things = Thing.where(:some_column => 'some_value').order(:priority).reverse

Thing is an activerecord model.

The weird thing is, when I restart the application the error disappears. It is only under some strange set of circumstances that this happens (which I can't reproduce in preprod/dev environments).

Has anyone come across something like this before? Can anyone suggest how I would go about diagnosing this bug? The line in question doesn't seem to be the problem (the logs in production also don't show the full stacktrace)


Solution

  • After a length hair pulling session, I discovered that this is due to a bug in rubinius (2.2.10, and 2.2.9). The ActiveRecord query methods where and order both call enumerable#grep internally. After the application has been running for some time, or some unknown conditions are met, this function stops behaving correctly when the array contains symbols.

    When a block is given as an argument to the grep function, this block will always be applied to the symbol elements of the array, regardless of the pattern given.

    Bug report is here