-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nil slices and empty slices are considered the same #366
Comments
Any update on this? This creates wierd behaviour and requires us to write cutsom marshal code for many structs. |
Possibly related, and a quick way to see the error: package main
import (
"testing"
"github.com/globalsign/mgo/bson"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type TestStruct struct {
Inner []bool
}
func TestUnmarshal(t *testing.T) {
a := TestStruct{}
aBSON, err := bson.Marshal(a)
require.NoError(t, err)
b := TestStruct{}
require.NoError(t, bson.Unmarshal(aBSON, &b))
assert.Equal(t, a, b)
} Will give the following test failure:
|
Oh, this isn't even an accident. This is on purpose.
|
Workaround: Wrap the
|
Probably related to: #147
I have a struct with:
I need to differentiate
bar == nil
orbar == []string{}
.When insert + findOne with a
nil
bar:When adding
omitempty
tag previous test will be okay but test on insert + findOne with a[]string{}
bar:I have to add a layer above to handle those cases properly, it would be more convenient (and not breaking ?) to handle this directly in the driver.
What version of MongoDB are you using (
mongod --version
)?What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
db.Insert
+db.Find
on an embed slice.Can you reproduce the issue on the latest
development
branch?yes
The text was updated successfully, but these errors were encountered: