fix(cloudcommon): panic when query an empty splitable model manager

fix panic when querying an empty splitable model manager, e.g. action-show
This commit is contained in:
Qiu Jian
2020-12-20 00:25:15 +08:00
parent ae107e334b
commit d01f89a2c8
5 changed files with 16 additions and 5 deletions
+6 -1
View File
@@ -611,7 +611,12 @@ func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok
}
union, err := sqlchemy.UnionWithError(subqs...)
if err != nil {
return nil, errors.Wrap(err, "sqlchemy.UnionWithError")
if errors.Cause(err) == sql.ErrNoRows {
emptyList := modulebase.ListResult{Data: []jsonutils.JSONObject{}}
return &emptyList, nil
} else {
return nil, errors.Wrap(err, "sqlchemy.UnionWithError")
}
}
q = union.Query()
} else {