Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1529

Support ActiveSupport::TimeWithZone serialization to BSON on bson-ruby level

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • bson-4.4.1
    • Affects Version/s: None
    • Component/s: BSON

      Currently Mongoid implements special handling for serialization of ActiveSupport::TimeWithZone objects to BSON, since this class does not derive from Time. Driver and bson library itself don't handle these objects specially. As a result, when querying data on a driver collection in a mongoid app (vs using a model) the query built is not correct.

      good_time = Time.now
      bad_time = Time.now.in_time_zone("Pacific Time (US & Canada)")
      User.collection.find(:u_at => {:$lt => bad_time}).to_a.length # this query will be wrong
      
      # the problem is that:
      good_time.to_bson != bad_time.to_bson
      

      A patch has been proposed in https://github.com/mongodb/bson-ruby/pull/104, however it couples bson-ruby too tightly to AS. My preference is to have a separate file for AS integration which Mongoid would require. The test suite in bson-ruby should also be run separately with and without having AS loaded.

      Lastly, code handling AS::TWZ in Mongoid should be examined to see if any of it should be moved to bson-ruby/driver or deleted, if driver/bson-ruby handle the serialization.

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: