From ea80274229bca259a64fed7eca181e4a82ff0676 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Mon, 29 Feb 2016 18:45:12 -0500 Subject: #2700 fix sqlite3 can't create issue with more than one label --- models/issue.go | 17 +++++++---------- models/repo.go | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'models') diff --git a/models/issue.go b/models/issue.go index 94998d783d..4c33bc6b26 100644 --- a/models/issue.go +++ b/models/issue.go @@ -297,20 +297,17 @@ func newIssue(e *xorm.Session, repo *Repository, issue *Issue, labelIDs []int64, return err } - var label *Label - for _, id := range labelIDs { - if id == 0 { - continue - } + // During the session, SQLite3 dirver cannot handle retrieve objects after update something. + // So we have to get all needed labels first. + labels := make([]*Label, 0, len(labelIDs)) + if err = e.In("id", labelIDs).Find(&labels); err != nil { + return fmt.Errorf("Find all labels: %v", err) + } - label, err = getLabelByID(e, id) - if err != nil { - return err - } + for _, label := range labels { if err = issue.addLabel(e, label); err != nil { return fmt.Errorf("addLabel: %v", err) } - } if issue.MilestoneID > 0 { diff --git a/models/repo.go b/models/repo.go index 75a4e66033..3011253d77 100644 --- a/models/repo.go +++ b/models/repo.go @@ -27,7 +27,7 @@ import ( "github.com/mcuadros/go-version" "gopkg.in/ini.v1" - "github.com/gogits/git-module" + git "github.com/gogits/git-module" api "github.com/gogits/go-gogs-client" "github.com/gogits/gogs/modules/bindata" -- cgit v1.2.3