bson.Raw unmarshals BSON null to Raw(nil) rather than Raw{}

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • None
    • Go Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Detailed steps to reproduce the problem?

      Run the following with v2.5.0:

      package main
      
      import (
      	"fmt"
      
      	"github.com/samber/lo"
      	"go.mongodb.org/mongo-driver/v2/bson"
      )
      
      func main() {
      	doc := bson.D{{"doc", nil}}
      	bin, err := bson.Marshal(doc)
      	lo.Assertf(err == nil, "marshal: %v", err)
      
      	rt := struct {
      		Doc bson.Raw
      	}{}
      	err = bson.Unmarshal(bin, &rt)
      	lo.Assertf(err == nil, "unmarshal: %v", err)
      
      	fmt.Printf("rt: %#v\n", rt.Doc)
      }
      

      You'll see:

      rt: bson.Raw{}

      Run it against v2.7.0 of the driver, though, and you'll see:

      rt: bson.Raw(nil)

      This behavior change, however subtle, seems an unintended effect of GODRIVER-3924.

      It’s a breaking change, and one that (AFAICT) doesn’t fix anything with regard to the driver spec, so per semver the v2 driver probably should revert to v2.5.0’s behavior. v2.7.0’s behavior should be part of driver v3.

      Definition of done: what must be done to consider the task complete?

      Either:

      1. Restore v2.5.0's behavior, OR:
      2. Determine that the new behavior—which, all things aside, does seem more sensible—is the new norm

      The exact Go version used, with patch level:

      1.26.3

      The exact version of the Go driver used:

      v2.5.0 & v2.7.0

      Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.

      n/a

      The operating system and version (e.g. Windows 7, OSX 10.8, ...)

      macOS Sequoia

      Security Vulnerabilities

      n/a

            Assignee:
            Matt Dale
            Reporter:
            Felipe Gasper
            None
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: