gastownhall/beads · error

query dependency targets: %w

Error message

query dependency targets: %w

What it means

This error wraps failure of the SELECT in replaceDependencyTargetInTx, which loads every edge in `table` (dependencies or wisp_dependencies) whose typed target column equals oldID (or whose generated target expression equals oldID with no external target). The rows are reinserted with the new target because Dolt can leave the generated depends_on_id column stale after an FK-cascade update.

Source

Thrown at internal/storage/issueops/dependencies.go:720

		issueTarget sql.NullString
		wispTarget  sql.NullString
		external    sql.NullString
		depType     string
		createdAt   sql.NullTime
		createdBy   sql.NullString
		metadata    sql.NullString
		threadID    sql.NullString
	}

	rows := make([]depRow, 0)
	//nolint:gosec // table and column are hardcoded by callers.
	queryRows, err := tx.QueryContext(ctx, fmt.Sprintf(`
		SELECT issue_id, depends_on_issue_id, depends_on_wisp_id, depends_on_external, type, created_at, created_by, metadata, thread_id
		FROM %s
		WHERE %s = ? OR (%s = ? AND depends_on_external IS NULL)
	`, table, column, DepTargetExpr), oldID, oldID)
	if err != nil {
		return fmt.Errorf("query dependency targets: %w", err)
	}
	for queryRows.Next() {
		var row depRow
		if err := queryRows.Scan(&row.issueID, &row.issueTarget, &row.wispTarget, &row.external, &row.depType, &row.createdAt, &row.createdBy, &row.metadata, &row.threadID); err != nil {
			_ = queryRows.Close()
			return fmt.Errorf("scan dependency target: %w", err)
		}
		switch column {
		case "depends_on_issue_id":
			row.issueTarget = sql.NullString{String: newID, Valid: true}
			row.wispTarget = sql.NullString{}
			row.external = sql.NullString{}
		case "depends_on_wisp_id":
			row.issueTarget = sql.NullString{}
			row.wispTarget = sql.NullString{String: newID, Valid: true}
			row.external = sql.NullString{}
		default:
			_ = queryRows.Close()

View on GitHub (pinned to 71377f2769)

Solutions

  1. Read the wrapped driver error after the colon for the root cause
  2. Migrate the schema so both dependencies and wisp_dependencies have all selected columns
  3. Reconnect/retry; the transaction rolls back atomically on failure
  4. If the tx is poisoned by an earlier error, fix that first

Example fix

// before: schema missing thread_id column
SELECT ..., thread_id FROM wisp_dependencies WHERE depends_on_issue_id = ?
-- Error: Unknown column 'thread_id' in 'field list'
// after: bring schema current
bd migrate && bd doctor
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify both target tables expose every selected column
for _, table := range []string{"dependencies", "wisp_dependencies"} {
    var n int
    db.Get(&n, `SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_NAME=? AND COLUMN_NAME IN
      ('issue_id','depends_on_issue_id','depends_on_wisp_id','depends_on_external','type','created_at','created_by','metadata','thread_id')`, table)
    if n < 9 { return fmt.Errorf("%s schema incomplete (%d/9); run bd migrate", table, n) }
}

Try / catch

err := updateIssueOrWispID(tx, oldID, newID)
if err != nil {
    if isAbortedTxError(err) {
        return fmt.Errorf("transaction already aborted by earlier statement; fix root cause before retrying: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: UpdateIssueIDInTx or UpdateWispIDInTx rename, when tx.QueryContext on the parameterized SELECT over dependencies/wisp_dependencies fails: missing table/columns, aborted transaction, or dropped connection.

Common situations: Out-of-date schema missing depends_on_wisp_id / depends_on_external / thread_id columns; connection reset during a bulk rename; a previous statement in the same tx already failed.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/e063b26971353d6e. Report an issue: GitHub.