[GODRIVER-719] Map Decoder should support non-primitive string types Created: 18/Dec/18 Updated: 28/Oct/23 Resolved: 07/Jan/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | BSON |
| Affects Version/s: | 0.1.0 |
| Fix Version/s: | 0.2.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Aleix Ventayol | Assignee: | Kristofer Brandow (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Ubuntu via WSL on Windows |
||
| Attachments: |
|
| Description |
|
The map decoder attempts to set the key of a map value as a string. When the key type is instead a non-primitive string type, e.g. type mystring string, the map decoder panics because it does not first convert the string value of the BSON to the appropriate type. To fix this, convert the BSON key string to the map's key type before setting. (original description below) I've a function that finds an item on the database, but I get a reflection error when trying to decode it. This is the error I get: reflect.Value.SetMapIndex: value of type string is not assignable to type models.DataType
And here you have the code I use to find the element on the database:
I attach the two models related to the problem, the device has a map where the map index is not a string but a custom type defined as string. I was using mgo driver without any problems before, but after migration to this official driver when I try to run my code I get a runtime exception. |
| Comments |
| Comment by Githook User [ 07/Jan/19 ] |
|
Author: {'username': 'skriptble', 'email': 'kris@mongodb.com', 'name': 'Kris Brandow'}Message: Ensure map decoder handles non-primitive strings Change-Id: Id3d57e5bb8a5eb09bb18684bfe962735ef597ee6 |
| Comment by Kristofer Brandow (Inactive) [ 04/Jan/19 ] |
|
Code Review: https://review.gerrithub.io/c/mongodb/mongo-go-driver/+/439194. |
| Comment by Aleix Ventayol [ 04/Jan/19 ] |
|
Let me know if you need me to test anything, I happy to help. |
| Comment by Kristofer Brandow (Inactive) [ 04/Jan/19 ] |
|
Hi ventayol, Thanks for the bug report, this is an issue. I'll work on a fix for this. --Kris |