Fix session insert interface slice commit panic(#2259) #2260
|
@ -185,3 +185,36 @@ func TestMultipleTransaction(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 0, len(ms))
|
assert.EqualValues(t, 0, len(ms))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInsertMulti2InterfaceTransaction(t *testing.T) {
|
||||||
|
|
||||||
|
type Multi2InterfaceTransaction struct {
|
||||||
lunny marked this conversation as resolved
Outdated
|
|||||||
|
ID uint64 `xorm:"id pk autoincr"`
|
||||||
|
Name string
|
||||||
|
Alias string
|
||||||
|
CreateTime time.Time `xorm:"created"`
|
||||||
|
UpdateTime time.Time `xorm:"updated"`
|
||||||
|
}
|
||||||
|
assert.NoError(t, PrepareEngine())
|
||||||
|
assertSync(t, new(Multi2InterfaceTransaction))
|
||||||
|
session := testEngine.NewSession()
|
||||||
|
defer session.Close()
|
||||||
|
err := session.Begin()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
users := []interface{}{
|
||||||
|
&Multi2InterfaceTransaction{Name: "a", Alias: "A"},
|
||||||
|
&Multi2InterfaceTransaction{Name: "b", Alias: "B"},
|
||||||
|
&Multi2InterfaceTransaction{Name: "c", Alias: "C"},
|
||||||
|
&Multi2InterfaceTransaction{Name: "d", Alias: "D"},
|
||||||
|
}
|
||||||
|
cnt, err := session.Insert(&users)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, len(users), cnt)
|
||||||
|
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
err = session.Commit()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -89,6 +89,8 @@ func (col *Column) ValueOfV(dataStruct *reflect.Value) (*reflect.Value, error) {
|
||||||
v.Set(reflect.New(v.Type().Elem()))
|
v.Set(reflect.New(v.Type().Elem()))
|
||||||
}
|
}
|
||||||
v = v.Elem()
|
v = v.Elem()
|
||||||
|
} else if v.Kind() == reflect.Interface {
|
||||||
|
v = reflect.Indirect(v.Elem())
|
||||||
}
|
}
|
||||||
v = v.FieldByIndex([]int{i})
|
v = v.FieldByIndex([]int{i})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user
Please use a special struct name so that gob will not be conflicted.
ok, i will change this struct name,thanks