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

BSON::Document#merge yields

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • bson-3.2.4
    • Affects Version/s: bson-3.2.0, bson-3.2.2
    • Component/s: BSON
    • Labels:
      None
    • Major Change

      We've noticed a regression while upgrading to bson 3.2.3 from bson 1.8: BSON::Document#merge yields to the provided block even when the key is not present in both hashes. This is incompatible with previous version of bson (at least 1.x) and most importantly Ruby's Hash#merge:

      Ruby only yields for keys present in both hashes:

      {a: 1}.merge(b: 1) { |k, old, new| old + new} # => {a: 1, b: 1}
      

      While bson 3 yields to #merge even if keys are not present in both hashes. This results in the following:

      a = BSON::Document.new(a: 1)
      
      a.merge(b: 1) { |k, old, new|  old + new } # => undefined method `+' for nil:NilClass
      

      I will submit a patch soon, that fixes the issue.

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            agis Agis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: