xxxxx.ToDB called using nil when Update() #1785

Closed
opened 2020-09-07 19:24:22 +00:00 by RelicOfTesla · 1 comment
// xorm 1.0.4


type TestFieldType1 struct {
	cb []byte
}

func (a *TestFieldType1) FromDB(src []byte) error {
	a.cb = src
	return nil
}

func (a TestFieldType1) ToDB() ([]byte, error) {
	return a.cb, nil
}

type TestTable1 struct {
	Id         int
	Field1     *TestFieldType1 `xorm:"text"`   // !!! can not use pointer when call update()
	UpdateTime time.Time
}

func TestNilFromDb(t *testing.T) {
	db := getTestDb()
	//db.Sync2(TestTable1{})
	n, err := db.Update(TestTable1{
		UpdateTime: time.Now(),  // i will only set update_time field...don't update field1 please...
		//Field1:     &TestFieldType1{cb: []byte("aa")},  // crash!! must require fill something this field 
	}, TestTable1{
		Id: 1,
	})
	t.Log(n, err)
}

// 	panic: value method /app/utils/test1.TestFieldType1.ToDB called using nil *TestFieldType1 pointer


```go // xorm 1.0.4 type TestFieldType1 struct { cb []byte } func (a *TestFieldType1) FromDB(src []byte) error { a.cb = src return nil } func (a TestFieldType1) ToDB() ([]byte, error) { return a.cb, nil } type TestTable1 struct { Id int Field1 *TestFieldType1 `xorm:"text"` // !!! can not use pointer when call update() UpdateTime time.Time } func TestNilFromDb(t *testing.T) { db := getTestDb() //db.Sync2(TestTable1{}) n, err := db.Update(TestTable1{ UpdateTime: time.Now(), // i will only set update_time field...don't update field1 please... //Field1: &TestFieldType1{cb: []byte("aa")}, // crash!! must require fill something this field }, TestTable1{ Id: 1, }) t.Log(n, err) } // panic: value method /app/utils/test1.TestFieldType1.ToDB called using nil *TestFieldType1 pointer ```
lunny added the
kind
bug
label 2020-09-08 01:33:38 +00:00
lunny added this to the 1.0.5 milestone 2020-09-08 01:33:41 +00:00
Author

same with Insert() and more

//xorm@v1.0.4/internal/statements/values.go:40 

if fieldConvert, ok := fieldValue.Interface().(convert.Conversion); ok {
		data, err := fieldConvert.ToDB()
		if err != nil {
        
same with Insert() and more ```go //xorm@v1.0.4/internal/statements/values.go:40 if fieldConvert, ok := fieldValue.Interface().(convert.Conversion); ok { data, err := fieldConvert.ToDB() if err != nil { ```
lunny closed this issue 2020-09-08 15:40:30 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1785
No description provided.