-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
(copied to CRM)
-
None
-
Go Drivers
-
Not Needed
-
None
-
None
-
None
-
None
-
None
-
None
Detailed steps to reproduce the problem?
func TestDoubleDecoding(t *testing.T) { client, err := mongo.Connect(...) require.NoError(t, err) defer func() { err := client.Disconnect(context.Background()) require.NoError(t, err) }() coll := client.Database("test").Collection("test") type Data struct { Content []interface{} `bson:"content"` } doc := Data{ Content: []interface{}{1, 2, 3}, } _, err = coll.InsertOne(context.Background(), doc) if err != nil { t.Fatalf("InsertOne failed: %v", err) } t.Run("case1", func(t *testing.T) { result := Data{ Content: []interface{}{7, 8, 9}, } err = coll.FindOne(context.Background(), bson.D{}).Decode(&result) if err != nil { t.Fatalf("FindOne failed: %v", err) } t.Log(result) }) t.Run("case2", func(t *testing.T) { v := 7 result := Data{ Content: []interface{}{&v}, } err = coll.FindOne(context.Background(), bson.D{}).Decode(&result) if err != nil { t.Fatalf("FindOne failed: %v", err) } t.Log(result) }) }
Definition of done: what must be done to consider the task complete?
- "case1" passes in v1 but not v2.
- The error message from "case1" is "IntDecodeValue can only decode valid and settable int8, int16, int32, int64, int, but got int32", which can be improved to indicate the call fails due to the unsettable value rather than the int32 type.
- The decode behavior in both cases does not align with json.Decode().
The exact version of the Go driver used:
v2
- is related to
-
GODRIVER-2382 Unmarshaling BSON into a struct with interface fields containing concrete value types doesn't work as expected.
-
- Closed
-