[GODRIVER-317] Handle nil properties of a struct in the BSON encoder Created: 27/Mar/18 Updated: 01/Oct/18 Resolved: 05/Apr/18 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | None |
| Affects Version/s: | 0.0.2 |
| Fix Version/s: | 0.0.3 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Kristofer Brandow (Inactive) | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Epic Link: | GODRIVER Alpha UX | ||||||||||||||||
| Description |
|
The BSON encoder does not handle struct properties that can be nil. If it does encounter a nil struct property it returns an error when it should encode that value into a BSON Null. To fix this:
|
| Comments |
| Comment by Travis Terry [ 01/Oct/18 ] |
|
This is still an issue with the StructCodec when trying to encode a struct that has a field which is a pointer to another struct. If the pointer is nil, it fails to encode here https://github.com/mongodb/mongo-go-driver/blob/master/bson/bsoncodec/struct_codec.go#L50. That needs a val.IsNil() check. Also, it took me a long time to track this down. I see that you return an error that the encoder "can only process structs," but that error is later replaced by a more generic error "failed to encode." Returning the more specific error would have made this a lot easier to find.
|
| Comment by Githook User [ 05/Apr/18 ] |
|
Author: {'email': 'kris@mongodb.com', 'name': 'Kris Brandow', 'username': 'skriptble'}Message: Handle nil properly in BSON encoder Added support for nil interfaces, maps, pointers, and slices. Change-Id: I96036138acb745b1f42d3190e9664366bb85a9a6 |
| Comment by Kristofer Brandow (Inactive) [ 03/Apr/18 ] |
|
Code Review: https://review.gerrithub.io/c/406250/. |
| Comment by Kristofer Brandow (Inactive) [ 27/Mar/18 ] |
|
This bug will cause problems with some of our internal types that use pointers if we ever try to marshal them, so scheduling this. |