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

Hash.from_bson can produce DBRef which isn't a subclass of Hash

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • bson-4.13.0
    • Affects Version/s: None
    • Component/s: BSON
    • Labels:
      None

      Driver's DBRef class overrides Hash.from_bson to specially handle hashes with $ref keys and produce a DBRef in this case.

       

      Unfortunately, DBRef is not a subclass of Hash, which can cause problems because now the type of return value of from_hash depends on the data being deserialized.

       

      This probably should be repaired as part of common DBRef work.

      Note that the override happens in the driver, not in bson-ruby.

       

      irb(main):007:0> e={'$ref'=>'x','$id'=>123,'x'=>42}
      => {"$ref"=>"x", "$id"=>123, "x"=>42}
      irb(main):011:0> Hash.from_bson(BSON::ByteBuffer.new(e.to_bson.to_s)).is_a?(Hash)
      => false
      
       

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

              Created:
              Updated:
              Resolved: