[GODRIVER-731] Maps inside structs are not zeroed Created: 20/Dec/18 Updated: 28/Oct/23 Resolved: 12/Feb/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | BSON |
| Affects Version/s: | 0.1.0 |
| Fix Version/s: | 1.0.0-rc1 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | David Golden | Assignee: | Divjot Arora (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
A map inside a struct is not zeroed on decoding. For example, given this type:
and this code:
The bson.M fields of the struct will not be zeroed and will accumulate data as the iterator progresses. This may surprise users who expect the struct. (In this case, the correct approach is to allocate a fresh struct inside the loop.) This should be documented. Another option might be to add a struct tag to request that a map field be zeroed. |
| Comments |
| Comment by Githook User [ 11/Feb/19 ] |
|
Author: {'name': 'Divjot Arora', 'email': 'divjot.arora@10gen.com', 'username': 'divjotarora'}Message: Document behavior of default struct decoder for maps and slices. Change-Id: I15ce9d98f737871f6d2b80af413ac3d043b2dd00 |
| Comment by David Golden [ 08/Feb/19 ] |
|
After discussion, I think we should just document the behavior and leave the behavior matching encoding/json. |
| Comment by Divjot Arora (Inactive) [ 07/Feb/19 ] |
|
Looked further into this. The behavior we have for maps and slices matches the behavior of encoding/json (add fields to an existing map and clear away an existing slice). Not sure what has to be done here - we can either just update the documentation to make this behavior known or change the behavior to not match encoding/json. david.golden kris.brandow |
| Comment by Jeffrey Yemin [ 20/Dec/18 ] |
|
Changing type to Improvement as I believe this is the intended behavior. |