{"record":{"id":"deb02dbcdadf6088","repo":"gastownhall/beads","slug":"query-dependents-for-batch-from-s-w","errorCode":null,"errorMessage":"query dependents for batch from %s: %w","messagePattern":"query dependents for batch from (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/delete.go","lineNumber":435,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"cascade traversal discovered over %d issues; aborting to prevent runaway deletion\", maxRecursiveResults)\n\t\t}\n\t\tbatchEnd := deleteBatchSize\n\t\tif batchEnd > len(toProcess) {\n\t\t\tbatchEnd = len(toProcess)\n\t\t}\n\t\tbatch := toProcess[:batchEnd]\n\t\ttoProcess = toProcess[batchEnd:]\n\n\t\tinClause, args := buildSQLInClause(batch)\n\t\tfor _, depTable := range []string{\"dependencies\", \"wisp_dependencies\"} {\n\t\t\trows, err := tx.QueryContext(ctx,\n\t\t\t\tfmt.Sprintf(`SELECT issue_id FROM %s WHERE %s`, depTable, depTargetIn(\"\", inClause)),\n\t\t\t\targs...)\n\t\t\tif err != nil {\n\t\t\t\tif optionalBlockedTable(depTable) && isTableNotExistError(err) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"query dependents for batch from %s: %w\", depTable, err)\n\t\t\t}\n\n\t\t\tfor rows.Next() {\n\t\t\t\tvar depID string\n\t\t\t\tif err := rows.Scan(&depID); err != nil {\n\t\t\t\t\t_ = rows.Close()\n\t\t\t\t\treturn nil, fmt.Errorf(\"scan dependent: %w\", err)\n\t\t\t\t}\n\t\t\t\tif !result[depID] {\n\t\t\t\t\tresult[depID] = true\n\t\t\t\t\ttoProcess = append(toProcess, depID)\n\t\t\t\t}\n\t\t\t}\n\t\t\t_ = rows.Close()\n\t\t\tif err := rows.Err(); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"iterate dependents for batch from %s: %w\", depTable, err)\n\t\t\t}\n\t\t}","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/delete.go#L417-L453","documentation":"FindAllDependentsInTx queries the dependencies/wisp_dependencies tables in batches to find dependents. A query error on a required table (one that is not an optional/absent table) is wrapped with this message naming the table. Table-not-exist errors are tolerated only for optional tables.","triggerScenarios":"ResolveDeletionSetInTx cascade traversal where SELECT issue_id FROM dependencies (or wisp_dependencies) fails — table does not exist and is not marked optional, SQL error, lock contention, or connection failure.","commonSituations":"Partially migrated or corrupted database missing a dependencies table; remote Dolt server connection reset mid-traversal; database locked by a concurrent writer.","solutions":["Read the wrapped driver error; if the table is missing, run schema migration (bd doctor/migrate)","Retry after resolving lock contention or restoring the connection","Verify wisp_dependencies presence if you use wisp mode and it is treated as required"],"exampleFix":"// before\nrows, err := tx.QueryContext(ctx, fmt.Sprintf(`SELECT issue_id FROM %s WHERE %s`, depTable, depTargetIn(\"\", inClause)), args...)\n// after — ensure schema is current first\n// bd doctor; bd migrate (or equivalent) before retrying cascade delete","handlingStrategy":"try-catch","validationCode":"// verify required dependency tables exist before cascade delete\nfor _, t := range []string{\"dependencies\"} {\n\tvar n int\n\tdb.QueryRow(\"SELECT COUNT(*) FROM sqlite_master WHERE name=?\", t).Scan(&n)\n\tif n == 0 { return fmt.Errorf(\"missing table %s; migrate first\", t) }\n}","typeGuard":null,"tryCatchPattern":"_, err := DeleteIssuesInTx(ctx, tx, ids, WithCascade())\nif err != nil && strings.Contains(err.Error(), \"query dependents for batch from\") {\n\tif strings.Contains(err.Error(), \"no such table\") { migrate(db); return retry(ctx, ids) }\n\treturn err\n}","preventionTips":["Keep schema migrations current with the binary version","Avoid concurrent writers during cascade deletes","Check connection stability to remote Dolt before large traversals"],"tags":["database","sql","cascade","dependency-graph"],"backgroundTag":"sql-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}