-
Notifications
You must be signed in to change notification settings - Fork 824
Closed
Description
Describe the bug
Using a uuid.UUID field works well with the in memory docstore but not with a mongodb instance.
To Reproduce
Startup a local mongodb instance. E.g.:
docker run -it --rm --net=host mongo
And run the following short test programm
package main
import (
"context"
"fmt"
"os"
"github.com/google/uuid"
"gocloud.dev/docstore"
_ "gocloud.dev/docstore/memdocstore"
_ "gocloud.dev/docstore/mongodocstore"
)
type Item struct {
Id uuid.UUID
DocstoreRevision interface{}
}
func main() {
memCollection, err := docstore.OpenCollection(context.Background(), "mem://Items/Id")
if err != nil {
panic(err)
}
createAndQuery(memCollection)
os.Setenv("MONGO_SERVER_URL", "mongodb://localhost/db")
mongoCollection, err := docstore.OpenCollection(context.Background(), "mongo://db/Items?id_field=Id")
if err != nil {
panic(err)
}
createAndQuery(mongoCollection)
}
func createAndQuery(collection *docstore.Collection) {
ctx := context.Background()
item := &Item{Id: uuid.New()}
result := &Item{}
err := collection.Create(ctx, item)
if err != nil {
panic(err)
}
err = collection.Query().Get(ctx).Next(ctx, result)
if err != nil {
panic(err)
}
fmt.Println(result.Id)
}On my machine the programm panics when reading from the mongodb instance:
$ go run .
405eb3eb-a0c6-4233-8554-736e479ef2c5
panic: reflect.Set: value of type []uint8 is not assignable to type uuid.UUID
goroutine 1 [running]:
reflect.Value.assignTo(0xb0f3e0, 0xc00000e440, 0x97, 0xc1f60b, 0xb, 0xbda5a0, 0x0, 0xc00000e440, 0x0, 0x0)
/snap/go/current/src/reflect/value.go:2435 +0x405
reflect.Value.Set(0xbda5a0, 0xc0003a8200, 0x191, 0xb0f3e0, 0xc00000e440, 0x97)
/snap/go/current/src/reflect/value.go:1564 +0xbd
gocloud.dev/docstore/driver.decode(0xbda5a0, 0xc0003a8200, 0x191, 0xd95d40, 0xc00000e420, 0x1, 0xbda5a0)
/home/carsten/go/pkg/mod/gocloud.dev@v0.20.0/docstore/driver/codec.go:391 +0x193
gocloud.dev/docstore/driver.decodeStruct.func1(0xc2a843, 0x2, 0xd95d40, 0xc00000e420, 0x40f201, 0xc00006a301)
/home/carsten/go/pkg/mod/gocloud.dev@v0.20.0/docstore/driver/codec.go:679 +0x15d
gocloud.dev/docstore/mongodocstore.decoder.DecodeMap(0xb54500, 0xc000078780, 0x0, 0xc00006a3c0)
/home/carsten/go/pkg/mod/gocloud.dev/docstore/mongodocstore@v0.20.0/codec.go:242 +0x13c
gocloud.dev/docstore/driver.decodeStruct(0xb8a260, 0xc0003a8200, 0x199, 0xd95d40, 0xc00000e3e0, 0xc00035fcf8, 0xc00000e3e0)
/home/carsten/go/pkg/mod/gocloud.dev@v0.20.0/docstore/driver/codec.go:658 +0x17d
gocloud.dev/docstore/driver.Document.Decode(0xaffae0, 0xc0003a8200, 0x0, 0xb8a260, 0xc0003a8200, 0x199, 0xc0002a02a0, 0x2, 0x2, 0xd95d40, ...)
/home/carsten/go/pkg/mod/gocloud.dev@v0.20.0/docstore/driver/document.go:184 +0x145
gocloud.dev/docstore/mongodocstore.decodeDoc(0xc000078780, 0xaffae0, 0xc0003a8200, 0x0, 0xb8a260, 0xc0003a8200, 0x199, 0xc0002a02a0, 0x2, 0x2, ...)
/home/carsten/go/pkg/mod/gocloud.dev/docstore/mongodocstore@v0.20.0/codec.go:125 +0x11e
gocloud.dev/docstore/mongodocstore.(*docIterator).Next(0xc0000786f0, 0xd8ce60, 0xc0000a2000, 0xaffae0, 0xc0003a8200, 0x0, 0xb8a260, 0xc0003a8200, 0x199, 0xc0002a02a0, ...)
/home/carsten/go/pkg/mod/gocloud.dev/docstore/mongodocstore@v0.20.0/query.go:127 +0xeb
gocloud.dev/docstore.(*DocumentIterator).Next(0xc000078720, 0xd8ce60, 0xc0000a2000, 0xaffae0, 0xc0003a8200, 0x0, 0x0)
/home/carsten/go/pkg/mod/gocloud.dev@v0.20.0/docstore/query.go:234 +0x1f8
main.createAndQuery(0xc0002b2d80)
/home/carsten/projects/test/main.go:46 +0x205
main.main()
/home/carsten/projects/test/main.go:33 +0x118
exit status 2
Expected behavior
This should print the uuid of the items stored in the in memory instance and mongodb like:
010ce414-2d8e-4d21-9dc3-aabf6c55b317
adac3c1e-2b96-4274-a630-e590693da78e
Version
Which version(s) of the Go Cloud modules are you seeing the bug with?
$ go version
go version go1.15.6 linux/amd64
$ cat go.mod
module test
go 1.15
require (
github.com/google/uuid v1.1.1
gocloud.dev v0.20.0
gocloud.dev/docstore/mongodocstore v0.20.0
)
Metadata
Metadata
Assignees
Labels
No labels