wavetermdev/waveterm · error

bad parent oref type: %v

Error message

bad parent oref type: %v

What it means

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.

Source

Thrown at pkg/wstore/wstore_dbops.go:388

			}
			query := `
			SELECT json_extract(b.data, '$.parentoref') AS parentoref
			FROM db_block b
			WHERE b.oid = ?;`
			parentORef := tx.GetString(query, blockId)
			oref, err := waveobj.ParseORef(parentORef)
			if err != nil {
				return "", fmt.Errorf("bad block parent oref: %v", err)
			}
			if oref.OType == "tab" {
				return oref.OID, nil
			}
			if oref.OType == "block" {
				blockId = oref.OID
				iterNum++
				continue
			}
			return "", fmt.Errorf("bad parent oref type: %v", oref.OType)
		}
	})
}

func DBFindWorkspaceForTabId(ctx context.Context, tabId string) (string, error) {
	return WithTxRtn(ctx, func(tx *TxWrap) (string, error) {
		query := `
			WITH variable(value) AS (
				SELECT ?
			)
			SELECT w.oid
			FROM db_workspace w, variable
			WHERE EXISTS (
				SELECT 1
				FROM json_each(w.data, '$.tabids') AS je
				WHERE je.value = variable.value
			);
			`

View on GitHub (pinned to a4447c1563)

Solutions

  1. Correct the block's parentoref to point at a tab or containing block
  2. Re-parent the block through the normal layout operations so the chain ends at a tab
  3. Audit the DB for blocks whose parent type is not block/tab and migrate them
Defensive patterns

Strategy: validation

Validate before calling

oref, err := waveobj.ParseORef(parentORef)
if err == nil && oref.OType != "tab" && oref.OType != "block" {
	// re-parent the block before calling DBFindTabForBlockId
}

Try / catch

tabId, err := wstore.DBFindTabForBlockId(ctx, blockId)
if err != nil && strings.Contains(err.Error(), "bad parent oref type") {
	// attach the block to a tab via layout APIs and retry
}

Prevention

When it happens

Trigger: A block whose parentoref points at a non-tab, non-block object type (e.g. 'workspace:...' or 'window:...') encountered during DBFindTabForBlockId traversal.

Common situations: 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.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/cc2fde86cfebcb20. Report an issue: GitHub.