gastownhall/beads · error

get dependents from %s: %w

Error message

get dependents from %s: %w

What it means

GetDependentsWithMetadataInTx wraps the error from tx.QueryContext when the initial SELECT of dependent rows fails against one of the dependency tables ("dependencies" or "wisp_dependencies", named in the message). This is a query-execution failure, not a row-scan failure: the SQL never returned a usable row set.

Source

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

	return results, nil
}

// GetDependentsWithMetadataInTx returns issues that depend on the given issueID
// along with the dependency type. Works within an existing transaction.
//
//nolint:gosec // G201: table names come from WispTableRouting (hardcoded constants)
func GetDependentsWithMetadataInTx(ctx context.Context, tx DBTX, issueID string) ([]*types.IssueWithDependencyMetadata, error) {
	type depMeta struct {
		depID, depType string
	}

	// Query both dependency tables to find all dependents.
	var deps []depMeta
	for _, depTable := range []string{"dependencies", "wisp_dependencies"} {
		rows, err := tx.QueryContext(ctx, fmt.Sprintf(
			`SELECT issue_id, type FROM %s WHERE %s = ?`, depTable, DepTargetExpr), issueID)
		if err != nil {
			return nil, fmt.Errorf("get dependents from %s: %w", depTable, err)
		}
		for rows.Next() {
			var d depMeta
			if scanErr := rows.Scan(&d.depID, &d.depType); scanErr != nil {
				_ = rows.Close()
				return nil, fmt.Errorf("get dependents: scan: %w", scanErr)
			}
			deps = append(deps, d)
		}
		_ = rows.Close()
		if err := rows.Err(); err != nil {
			return nil, fmt.Errorf("get dependents: rows from %s: %w", depTable, err)
		}
	}

	if len(deps) == 0 {
		return nil, nil
	}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Run the failing SELECT manually against the named table to reproduce the driver error.
  2. Verify both dependencies and wisp_dependencies tables exist and are migrated to the current schema version.
  3. Check DB user permissions on both dependency tables.
  4. Check connection health and context deadline; reconnect/retry if the error is transient.

Example fix

// before: partial migration, wisp table missing
// after: ensure migrations run before storage use
if err := migrations.Apply(ctx, db); err != nil { return err }
deps, err := GetDependentsWithMetadataInTx(ctx, tx, issueID)
Defensive patterns

Strategy: validation

Validate before calling

// Verify both dependency tables exist before querying dependents
var n int
for _, t := range []string{"dependencies", "wisp_dependencies"} {
    err := tx.QueryRowContext(ctx, `SELECT COUNT(*) FROM information_schema.tables WHERE table_name = ?`, t).Scan(&n)
    if err != nil || n == 0 { return fmt.Errorf("table %s missing; run migrations", t) }
}

Type guard

func isQueryExecErr(err error) bool {
    return err != nil && strings.Contains(err.Error(), "from dependencies") || strings.Contains(err.Error(), "from wisp_dependencies")
}

Try / catch

deps, err := GetDependentsWithMetadataInTx(ctx, tx, issueID)
if err != nil {
    var mysqlErr *mysql.MySQLError
    if errors.As(err, &mysqlErr) && mysqlErr.Number == 1146 {
        return fmt.Errorf("schema not migrated: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling GetDependentsWithMetadataInTx (via buildDependencyTreeInTx or ExecuteRelated) when the SELECT issue_id, type FROM <table> WHERE <target> = ? statement fails — missing table, bad connection, syntax/permission error, or cancelled context.

Common situations: Running against a database migrated from an older version where wisp_dependencies doesn't exist yet; insufficient privileges on one table; dead connection pool after idle timeout; schema drift between environments.

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/29eb5627ac06ee4c. Report an issue: GitHub.