Conversation
LightJack05
commented
Jan 27, 2026
- apparently a quantity can be a string and therefore should be deserialized as such
There was a problem hiding this comment.
Pull request overview
Updates the Product data model to treat product_quantity as a string instead of a number, based on upstream data sometimes representing quantity as text.
Changes:
- Changed
Product.ProductQuantitytype fromfloat64tostringfor JSON/BSON decoding.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| FoodGroupsTags []interface{} `json:"food_groups_tags" bson:"food_groups_tags,truncate"` | ||
| States string `json:"states" bson:"states"` | ||
| ProductQuantity float64 `json:"product_quantity" bson:"product_quantity,truncate"` | ||
| ProductQuantity string `json:"product_quantity" bson:"product_quantity,truncate"` |
There was a problem hiding this comment.
Changing ProductQuantity from float64 to string will likely break BSON decoding from MongoDB when existing documents store product_quantity as a numeric type (and vice versa if some docs store it as a string). The Go MongoDB driver cannot decode a BSON double/int directly into a Go string, so FindOne().Decode()/cursor.All() can start failing at runtime for mixed-type data. Consider introducing a dedicated type for this field that implements BSON unmarshalling (and JSON unmarshalling if needed) to accept both string and numeric representations and normalize to a string, rather than switching the struct field to plain string.
| FoodGroupsTags []interface{} `json:"food_groups_tags" bson:"food_groups_tags,truncate"` | ||
| States string `json:"states" bson:"states"` | ||
| ProductQuantity float64 `json:"product_quantity" bson:"product_quantity,truncate"` | ||
| ProductQuantity string `json:"product_quantity" bson:"product_quantity,truncate"` |
There was a problem hiding this comment.
bson:"product_quantity,truncate" was previously meaningful for a numeric type; on a string field it’s inconsistent with the rest of this struct (no other string fields use truncate) and can be misleading. Recommend dropping the truncate option if the field remains non-numeric, or keeping the field numeric internally and converting at the API boundary.
| ProductQuantity string `json:"product_quantity" bson:"product_quantity,truncate"` | |
| ProductQuantity string `json:"product_quantity" bson:"product_quantity"` |