[GODRIVER-1576] Allowing pointer of type to implement an interface causes errors for non-addressable types Created: 14/Apr/20  Updated: 28/Oct/23  Resolved: 24/Apr/20

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.3.3

Type: Bug Priority: Major - P3
Reporter: Divjot Arora (Inactive) Assignee: Isabella Siu (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

In GODRIVER-1356, we allowed a pointer to a type to implement the hooks we check for during BSON encoding/decoding (e.g. bsoncodec.Marshaler). This causes problems if the value being marshalled isn't addressable but a pointer to the value implements the hook. The registry will return the codec for the hook, but the codec will error because val.CanAddr returns false. See https://play.golang.org/p/GwmqXl5sFAx for a repro.

As a side-note, I don't really understand why the value isn't addressable. Unfortunately, the registry does lookups using reflect.Type so it doesn't have enough information to know if the value is addressable or not.



 Comments   
Comment by Githook User [ 24/Apr/20 ]

Author:

{'name': 'iwysiu', 'email': 'isabella.siu@10gen.com', 'username': 'iwysiu'}

Message: GODRIVER-1576 fix non-addr type with pointer implementation for bson (#379)
Branch: release/1.3
https://github.com/mongodb/mongo-go-driver/commit/237abe95be54a5f2adceb03eb4a9ea70147a6b6c

Comment by Githook User [ 24/Apr/20 ]

Author:

{'name': 'iwysiu', 'email': 'isabella.siu@10gen.com', 'username': 'iwysiu'}

Message: GODRIVER-1576 fix non-addr type with pointer implementation for bson (#379)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/e55c6c9c10e201c9fe212ee67c988d508aff4202

Generated at Thu Feb 08 08:36:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.