[GODRIVER-1350] Zeroer improvement causes primitive.Binary with no data to be zeroed to nil Created: 18/Oct/19  Updated: 27/Oct/23  Resolved: 25/Oct/19

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

Type: Bug Priority: Major - P3
Reporter: Eric Daniels (Inactive) Assignee: Divjot Arora (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

It used to be the case that unmarshaling absent data for a field onto a primitive.Binary would set Data to []uint8{} but now it is being set to []uint8(nil).



 Comments   
Comment by Divjot Arora (Inactive) [ 22/Oct/19 ]

Ah, I was missing the omitempty part. I think I understand this now. Before GODRIVER-990 was done, the omitempty tag didn't really mean anything for primitive.Binary, or any other fields that are structs. This is because our BSON encoding/decoding machinery doesn't test if structs are "empty" unless they implement the bson.Zeroer interface so a primitive.Binary field with no subtype and no data would still be marshalled/unmarshalled. If skipping empty primitive.Binary fields is not the desired behavior, the omitempty tag shouldn't be used.

Comment by Eric Daniels (Inactive) [ 19/Oct/19 ]

So you need to be on master of driver and also do an omitempty tag on the binary field.

Comment by Divjot Arora (Inactive) [ 18/Oct/19 ]

eric.daniels I couldn't reproduce this. Can you look it over my attempted repro at https://play.golang.org/p/4-bVA89rx-U and let me know if my understanding of the ticket is wrong?

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