Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(issues): skip issues with a blocker conflict in batch updates (#11504)
pseudoyucd927bda32f9
diff --git a/server/internal/handler/issue.go b/server/internal/handler/issue.goindex d569881c08..986a2de0b6 100644--- a/server/internal/handler/issue.go+++ b/server/internal/handler/issue.go@@ -5363,9 +5363,14 @@ func (h *Handler) BatchUpdateIssues(w http.ResponseWriter, r *http.Request) {issue, labelsChanged, propertiesChanged = written.issue, written.labelsChanged, written.propertiesChanged}if err != nil {+ if message, ok := issueBlockerConflict(err); ok {+ skip(issueID, identifier, "blocker_conflict", message)+ continue+ }// The archive race is a property of the batch's shared target// status, not of one issue, so every remaining item would fail the// same way. Abort with 409 instead of reporting a partial update.+ // A blocker that does not exist is shared the same way.if writeIssueBlockerError(w, err) {return}diff --git a/server/internal/handler/issue_batch_ops_test.go b/server/internal/handler/issue_batch_ops_test.goindex 7d4217124d..16a4c234d0 100644--- a/server/internal/handler/issue_batch_ops_test.go+++ b/server/internal/handler/issue_batch_ops_test.go@@ -84,6 +84,49 @@ func setIssueParent(t *testing.T, issueID, parentID string) {}}+// A blocker conflict belongs to the issue it was found on: the issues around it+// are written and reported, like every other per-issue conflict.+func TestBatchUpdateSkipsBlockerConflicts(t *testing.T) {+ newIssue := func(t *testing.T, name string) string {+ id := createTestIssue(t, "BU-blocker "+name, "todo", "low")+ t.Cleanup(func() { deleteTestIssue(t, id) })+ return id+ }+ run := func(t *testing.T, before, conflicting, after string, updates map[string]any) {+ t.Helper()+ status, resp, raw := batchUpdate(t, map[string]any{+ "issue_ids": []string{before, conflicting, after},+ "updates": updates,+ })+ if status != http.StatusOK || resp.Updated != 2 {+ t.Fatalf("batch = %d %s, want 200 with 2 updated", status, raw)+ }+ for _, id := range []string{before, after} {+ if got := resultFor(t, resp, id); got.Outcome != batchOutcomeUpdated {+ t.Fatalf("issue %s = %+v, want updated", id, got)+ }+ }+ if got := resultFor(t, resp, conflicting); got.Outcome != batchOutcomeSkipped || got.Code != "blocker_conflict" || got.Message == "" {+ t.Fatalf("conflicting issue = %+v, want skipped with blocker_conflict", got)+ }+ }++ t.Run("blocked by itself", func(t *testing.T) {+ a, b, c := newIssue(t, "a"), newIssue(t, "b"), newIssue(t, "c")+ run(t, a, b, c, map[string]any{"blocked_by": []string{b}})+ })+ t.Run("cycle", func(t *testing.T) {+ a, b, c, gate := newIssue(t, "a"), newIssue(t, "b"), newIssue(t, "c"), newIssue(t, "gate")+ updateIssueForTest(t, gate, map[string]any{"blocked_by": []string{b}}).Want(http.StatusOK)+ run(t, a, b, c, map[string]any{"blocked_by": []string{gate}})+ })+ t.Run("parent it blocks", func(t *testing.T) {+ a, b, c, parent := newIssue(t, "a"), newIssue(t, "b"), newIssue(t, "c"), newIssue(t, "parent")+ updateIssueForTest(t, parent, map[string]any{"blocked_by": []string{b}}).Want(http.StatusOK)+ run(t, a, b, c, map[string]any{"parent_issue_id": parent})+ })+}+// A batch that cannot apply to every issue reports, per issue, which ones it// skipped and why, instead of only a short count. (MUL-8882)func TestBatchUpdateReportsSkippedIssues(t *testing.T) {diff --git a/server/internal/handler/issue_blocker.go b/server/internal/handler/issue_blocker.goindex 847a4dd58f..a3ae0dc8d4 100644--- a/server/internal/handler/issue_blocker.go+++ b/server/internal/handler/issue_blocker.go@@ -43,18 +43,30 @@ type IssueBlockerResponse struct {}func writeIssueBlockerError(w http.ResponseWriter, err error) bool {- if errors.Is(err, service.ErrIssueBlockerNotFound) || errors.Is(err, service.ErrIssueBlockerSelf) {+ if errors.Is(err, service.ErrIssueBlockerNotFound) {writeError(w, http.StatusBadRequest, err.Error())return true}- var pgErr *pgconn.PgError- if errors.As(err, &pgErr) && strings.HasPrefix(pgErr.ConstraintName, "issue_blocker_") {- writeError(w, http.StatusBadRequest, pgErr.Message)+ if message, ok := issueBlockerConflict(err); ok {+ writeError(w, http.StatusBadRequest, message)return true}return false}+// issueBlockerConflict reports a dependency rule the written issue itself would+// break, and the sentence to show for it.+func issueBlockerConflict(err error) (string, bool) {+ if errors.Is(err, service.ErrIssueBlockerSelf) {+ return err.Error(), true+ }+ var pgErr *pgconn.PgError+ if errors.As(err, &pgErr) && strings.HasPrefix(pgErr.ConstraintName, "issue_blocker_") {+ return pgErr.Message, true+ }+ return "", false+}+func (h *Handler) parseBlockerIDs(w http.ResponseWriter, values []string) ([]pgtype.UUID, bool) {if len(values) > 100 {writeError(w, http.StatusBadRequest, "at most 100 blockers per request")