{"record":{"id":"cc2fde86cfebcb20","repo":"wavetermdev/waveterm","slug":"bad-parent-oref-type-v","errorCode":null,"errorMessage":"bad parent oref type: %v","messagePattern":"bad parent oref type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wstore/wstore_dbops.go","lineNumber":388,"sourceCode":"\t\t\t}\n\t\t\tquery := `\n\t\t\tSELECT json_extract(b.data, '$.parentoref') AS parentoref\n\t\t\tFROM db_block b\n\t\t\tWHERE b.oid = ?;`\n\t\t\tparentORef := tx.GetString(query, blockId)\n\t\t\toref, err := waveobj.ParseORef(parentORef)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", fmt.Errorf(\"bad block parent oref: %v\", err)\n\t\t\t}\n\t\t\tif oref.OType == \"tab\" {\n\t\t\t\treturn oref.OID, nil\n\t\t\t}\n\t\t\tif oref.OType == \"block\" {\n\t\t\t\tblockId = oref.OID\n\t\t\t\titerNum++\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\treturn \"\", fmt.Errorf(\"bad parent oref type: %v\", oref.OType)\n\t\t}\n\t})\n}\n\nfunc DBFindWorkspaceForTabId(ctx context.Context, tabId string) (string, error) {\n\treturn WithTxRtn(ctx, func(tx *TxWrap) (string, error) {\n\t\tquery := `\n\t\t\tWITH variable(value) AS (\n\t\t\t\tSELECT ?\n\t\t\t)\n\t\t\tSELECT w.oid\n\t\t\tFROM db_workspace w, variable\n\t\t\tWHERE EXISTS (\n\t\t\t\tSELECT 1\n\t\t\t\tFROM json_each(w.data, '$.tabids') AS je\n\t\t\t\tWHERE je.value = variable.value\n\t\t\t);\n\t\t\t`","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wstore/wstore_dbops.go#L370-L406","documentation":"DBFindTabForBlockId expects every parent in the chain to be either a tab (success) or another block (continue walking). Any other parent oref type — e.g. workspace or window — is invalid for a block's parent and terminates the search with this error.","triggerScenarios":"A block whose parentoref points at a non-tab, non-block object type (e.g. 'workspace:...' or 'window:...') encountered during DBFindTabForBlockId traversal.","commonSituations":"Logic bugs that attach blocks directly to workspaces/windows; version changes in the object model leaving stale parent types in old databases; corrupted or hand-edited rows.","solutions":["Correct the block's parentoref to point at a tab or containing block","Re-parent the block through the normal layout operations so the chain ends at a tab","Audit the DB for blocks whose parent type is not block/tab and migrate them"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"oref, err := waveobj.ParseORef(parentORef)\nif err == nil && oref.OType != \"tab\" && oref.OType != \"block\" {\n\t// re-parent the block before calling DBFindTabForBlockId\n}","typeGuard":null,"tryCatchPattern":"tabId, err := wstore.DBFindTabForBlockId(ctx, blockId)\nif err != nil && strings.Contains(err.Error(), \"bad parent oref type\") {\n\t// attach the block to a tab via layout APIs and retry\n}","preventionTips":["Only attach blocks to tabs or containing blocks","Audit the DB for non-tab/non-block parents of blocks","Re-parent blocks through supported APIs after schema/version changes"],"tags":["sqlite","oref","object-model"],"backgroundTag":"invalid-parent-type","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}