[MM-28810] channel_store_categories: check if object is nil after the query (#15635)

* check if onj is nil

* channel_store_categories: add tests

* reflect review comments

* remove store declaraation
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2020-10-07 09:33:18 +03:00
коммит произвёл GitHub
родитель 6222e182ca
Коммит c67c46a684
3 изменённых файлов: 49 добавлений и 2 удалений

Просмотреть файл

@@ -6,10 +6,9 @@ package sqlstore
import (
"fmt"
"github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/gorp"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors"
@@ -843,6 +842,8 @@ func (s SqlChannelStore) addChannelToFavoritesCategoryT(transaction *gorp.Transa
var channel *model.Channel
if obj, err := transaction.Get(&model.Channel{}, preference.Name); err != nil {
return errors.Wrapf(err, "Failed to get favorited channel with id=%s", preference.Name)
} else if obj == nil {
return store.NewErrNotFound("Channel", preference.Name)
} else {
channel = obj.(*model.Channel)
}