globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 231 forks source link

*time.Duration not deserialized into milliseconds #335

Closed pkaeding closed 5 years ago

pkaeding commented 5 years ago

What version of MongoDB are you using (mongod --version)?

3.2.17

What version of Go are you using (go version)?

go version go1.11.1 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/patrickkaeding/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/patrickkaeding/prj/go/"
GOPROXY=""
GORACE=""
GOROOT="/Users/patrickkaeding/.gvm/gos/go1.11.1"
GOTMPDIR=""
GOTOOLDIR="/Users/patrickkaeding/.gvm/gos/go1.11.1/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/fg/8jsp2fjn3qzfscr5brx9r_gm0000gp/T/go-build819446042=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

This gist illustrates the issue: https://gist.github.com/pkaeding/b361060b3b56112dfe01b84942afe648

It seems that when a struct has a *time.Duration field, that value is serialized as a number of milliseconds, but deserialized as nanoseconds. If the field is a time.Duration (ie, not a pointer), then the round trip serialization/deserialization works fine.

Can you reproduce the issue on the latest development branch?

Yes, I get the same results with ae196ac5024de13358780893f917b65ec1d2a7be (development) and eeefdecb41b842af6dc652aaea4026e8403e62df (master)

Related: https://github.com/globalsign/mgo/issues/212

eminano commented 5 years ago

Hi @pkaeding,

Sorry for the delay!

I've tried reproducing the issue with the information provided, but the test in your gist is working for me (I'm using mgo version 3.2.21 instead of 3.2.17).

Did you manage to solve the problem?

Did you maybe try with a newer version of mgo? I'm not sure if that would help in this case, but the bson encoding/decoding hasn't been changed for a while so it doesn't seem like a library issue.

Thanks, Esther

eminano commented 5 years ago

I'll close this issue, please feel free to reopen if there's a problem with the driver. Thanks, Esther