bytebase/bytebase · error
found %v tasks with id %v
Error message
found %v tasks with id %v
What it means
GetTaskByID expects at most one task per (projectID, id); if ListTasks returns more than one it raises errors.Errorf "found %v tasks with id %v". This is an internal invariant violation: a project-scoped task ID must be unique, so duplicates indicate data corruption or a query that isn't filtering by project correctly.
Source
Thrown at backend/store/task.go:93
// TaskStatusCount holds aggregated task counts grouped by plan, environment and API-visible status.
type TaskStatusCount struct {
ProjectID string
PlanID int64
Environment string
Status string
Count int32
}
// GetTaskByID gets a task by ID.
func (s *Store) GetTaskByID(ctx context.Context, projectID string, id int64) (*TaskMessage, error) {
tasks, err := s.ListTasks(ctx, &TaskFind{ProjectID: projectID, ID: &id})
if err != nil {
return nil, errors.Wrapf(err, "failed to get Task with ID %d", id)
}
if len(tasks) == 0 {
return nil, nil
} else if len(tasks) > 1 {
return nil, errors.Errorf("found %v tasks with id %v", len(tasks), id)
}
return tasks[0], nil
}
// Get a blocking task in the pipeline.
// A task is blocked by a task with a smaller schema version within the same pipeline.
func (s *Store) FindBlockingTaskByVersion(ctx context.Context, projectID string, planUID int64, instanceID, databaseName string, version string) (*int64, error) {
myVersion, err := model.NewVersion(version)
if err != nil {
return nil, err
}
q := qb.Q().Space(`
SELECT
task.id,
task.payload->>'schemaVersion'
FROM task
LEFT JOIN plan ON plan.project = task.project AND plan.id = task.plan_id
LEFT JOIN issue ON issue.project = plan.project AND issue.plan_id = plan.idView on GitHub (pinned to 1870550677)
Solutions
- Query the task table for the duplicate: SELECT id, project FROM task WHERE id = <id>; remove or fix the offending duplicate rows.
- Confirm TaskFind is passing ProjectID so the query scopes by project.
- Check task table primary key/constraints in LATEST.sql against the live metadata DB — duplicates imply missing constraints from an unmigrated or altered DB.
Defensive patterns
Strategy: validation
Validate before calling
var n int _ = db.QueryRow(`SELECT COUNT(*) FROM task WHERE id = $1`, id).Scan(&n) // n > 1 means corrupted data: dedupe before calling GetTaskByID
Try / catch
task, err := store.GetTaskByID(ctx, projectID, id)
if err != nil {
if strings.Contains(err.Error(), "found ") && strings.Contains(err.Error(), "tasks with id") {
// dedupe task rows; don't retry — data corruption won't self-heal
}
return err
} Prevention
- Never drop or alter the task table's primary key.
- Always scope task lookups by ProjectID.
- After restoring/merging metadata databases, run integrity checks for duplicate IDs.
When it happens
Trigger: The task table contains duplicate rows with the same ID within a project (should be impossible with a proper primary key), or the ProjectID filter is not applied so tasks from other projects match the ID.
Common situations: Restored/merged metadata databases with inconsistent task rows; code changes that drop the ProjectID predicate from TaskFind; cross-project ID reuse assumptions.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- found %d changelogs with find %v, expect 1
- CONFLICT
- expected 1 sheet, got %d
- failed to get Task with ID %d
- expected to get one task run, but got %d
AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06).
Data as JSON: /api/errors/eff36baf717ad69e.
Report an issue: GitHub.