Beego: QuerySetter.All() is broken since the latest commits

Created on 24 Jul 2018  ·  7Comments  ·  Source: astaxie/beego

I've updated to the current master tree state and it seems like QuerySetter.All() method now returns error in case when no rows found instead of count=0 and error = nil.

├── Beego : 1.10.0
├── GoVersion : go1.10.3
├── GOOS : darwin
├── GOARCH : amd64
├── NumCPU : 8
├── GOPATH : /Users/ak/Dev/go
├── GOROOT : /usr/local/go
├── Compiler : gc
└── Date : Tuesday, 24 Jul 2018

How to reproduce: just create an empty table and define model for it. Then try to query it with QueryTable().All() and that's it:

package main

import (
    "log"

    "github.com/astaxie/beego/orm"
    _ "github.com/go-sql-driver/mysql"
)

func (f *MyTest) TableName() string {
    return "ftps2"
}

type MyTest struct {
    Id    int64  `orm:"column(id);"`
    Login string `orm:"unique"`
}

func main() {
    orm.RegisterDriver("mysql", orm.DRMySQL)
    orm.RegisterModel(new(MyTest))
    if err := orm.RegisterDataBase("default", "mysql", "root:@tcp(mysql:3306)/mydb?charset=utf8", 0, 50); err != nil {
        log.Fatalf("Error registering database: %s", err)
    }
    var tests []*MyTest
    t := new(MyTest)
    _, err := orm.NewOrm().QueryTable(t).All(&tests)
    if err != nil {
        log.Fatalf("Error reading tests: %s", err)
    }
}

then run it:

$ go run main.go
2018/07/24 11:50:15 Error reading tests: <QuerySeter> no row found
exit status 1

it should give no error and zero records instead.

Most helpful comment

I have craeted PR for reverting this change, looking forward to see it merged into master ASAP.

All 7 comments

Seems like it is because of #3247

Guys, I don't understand why it was necessary to add this feature since it really breaks old code even your own tests?

I have the same issue. When I reviewed my code today, I though it was a bug and didn't realize it is because the ORM code changed.

I think this commit should be reverted to be honest

I have craeted PR for reverting this change, looking forward to see it merged into master ASAP.

I am lost, is this issue fixed? can it be closed?

@mathieujobin Looks like it was reverted, so yes

why are the resolved issues remains open then?

Was this page helpful?
0 / 5 - 0 ratings