Skip to content

Invalid date_time comparison #9305

hickey opened this Issue Feb 16, 2013 · 5 comments

5 participants

hickey commented Feb 16, 2013

I am currently using mongo_mapper and for some reason I am getting a bad comparison of timestamps when ever a database record is read. The actual error message I receive is as follows:

Exception NoMethodError' at /Users/ghickey/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/core_ext/date_time/calculations.rb:142 - undefined methodcoerce' for nil:NilClass

In examining the calculations.rb file, the final method is

  def <=>(other)
    super other.to_datetime

I have been finding that other is not nil, but instead blank. Inserting a test for a blank value and returning a -1 does not throw an exception.

  def <=>(other)
    if other.blank?
      return -1
    super other.to_datetime

@hickey could not simulate your problem here. Please describe it better.

Thanks ..

@rafaelfranca , @carlosantoniodasilva puts this issues in label '3-2-stable', she is as 'master'. Thanks!

Ruby on Rails member

I wonder if this is somehow related to #2797 - @hickey do you use any gems that override <=> on DateTime ?


@hickey what gems you use?

I did some tests with Date, Time and DateTime in an application to use the mongoid, and had no problems.

JonRowe commented Mar 17, 2013

@hickey Mongo stores dates as times (or strings) and so there is conversion happening in Mongo and/or MongoMapper to produce dates into Rails. It is likely this is happening in a fashion that is bypassing the ActiveSupport extended Date hence the lack of coerce. Can you produce a failing test case for Rails? You could also ask the MongoMapper team for help on this.

Ruby on Rails member

@hickey it's been a few months since we've heard from you, and as @JonRowe mentions, it's quite possible this is a Mongo/MongoMapper issue. Unless we can prove somehow that this is actually a bug in Rails, I'm going to give this a close. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.