guregu / dynamo

expressive DynamoDB library for Go
Other
1.3k stars 179 forks source link

Put a embed struct, a panic occurs #247

Closed karasawako closed 1 month ago

karasawako commented 1 month ago

I have confirmed this with v2.2.0. If I put the following structure to DynamoDB, a panic occurs.

type ServerResponse struct {
    EmbeddedID int
}
type TestAddition struct {
    ServerResponse
}
type TestItem struct {
    ID int `dynamo:"id,hash" json:"id"`
    Name string `dynamo:"name,range" json:"name"`
    Addition TestAddition `dynamo:"addition,omitempty"`
}

tbl.Put(TestItem{ID: 1, Name: "test"}).Run(ctx)

This is because field.isZero == nil is set on line 257 of reflect.go. Is it possible to include an embed structure in Put?

guregu commented 1 month ago

Looks like a bug. Thanks for the report, I'll fix it.

guregu commented 1 month ago

I released v2.2.1 with a fix. Thanks again!

karasawako commented 1 month ago

Quick fix, thanks!