Skip to content
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

.Batch() no return err in some scenes #3086

Closed
LincolnHa opened this issue Oct 25, 2023 · 0 comments
Closed

.Batch() no return err in some scenes #3086

LincolnHa opened this issue Oct 25, 2023 · 0 comments
Assignees
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.

Comments

@LincolnHa
Copy link

1. What version of Go and system type/arch are you using?

go1.18.1, linux/amd64

2. What version of GoFrame are you using?

v2.5.3

3. Can this issue be re-produced with the latest release?

yes

4. What did you do?

// Uid is not allowed to be null in MySQL
type User struct {
    g.Meta   `orm:"table:user, do:true"`
    Uid      interface{} // User ID
    Name  interface{} // User Nickname
}
// Construct a list that does not comply with MySQL constraints
// The first user is incorrect data, and the second user is correct
list := []*User{
    {
        Uid:  nil,
        Name: "john",
    },
    {
        Uid:  1,
        Name: "john",
    },    
}

err:=g.Model("user").Data(list).Batch(10).Insert()
if err !=nil {
    painc(err)
}

5. What did you expect to see?

panic err

6. What did you see instead?

mysql has no data, and the console also prints an error, but in fact err is nil

7. The problematic code

https://github.com/gogf/gf/blob/master/database/gdb/gdb_core.go#L468C3-L481C25

KeyListMap.Size() > 1, and c.DoInsert will be executed twice, and when the first iteration failed, return &sqlResult, nil will set err to nil, causing err not to return

8. How to solve it

return &sqlResult, err
@gqcn gqcn added the bug It is confirmed a bug, but don't worry, we'll handle it. label Oct 25, 2023
@gqcn gqcn self-assigned this Oct 25, 2023
gqcn added a commit that referenced this issue Oct 25, 2023
@gqcn gqcn added the done This issue is done, which may be release in next version. label Oct 25, 2023
@gqcn gqcn closed this as completed Oct 25, 2023
gqcn added a commit that referenced this issue Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.
Projects
None yet
Development

No branches or pull requests

2 participants