{"record":{"id":"c8ce8814bce9068c","repo":"siyuan-note/siyuan","slug":"clone-attribute-view-text-value-s-failed","errorCode":null,"errorMessage":"clone attribute view text value [%s] failed","messagePattern":"clone attribute view text value \\[(.+?)\\] failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view.go","lineNumber":8158,"sourceCode":"\tvar oldRelationBlockIDs []string\n\tif av.KeyTypeRelation == val.Type {\n\t\tif nil != val.Relation {\n\t\t\tfor _, bID := range val.Relation.BlockIDs {\n\t\t\t\toldRelationBlockIDs = append(oldRelationBlockIDs, bID)\n\t\t\t}\n\t\t}\n\t}\n\tdata, err := gulu.JSON.MarshalJSON(valueData)\n\tif err != nil {\n\t\tlogging.LogErrorf(\"marshal value [%+v] failed: %s\", valueData, err)\n\t\treturn\n\t}\n\tupdatedVal := val\n\t// 文本和主键值先在副本上合并和校验，避免校验失败污染原值，并保留部分更新语义。\n\tif av.KeyTypeText == valueType || av.KeyTypeBlock == valueType {\n\t\tupdatedVal = val.Clone()\n\t\tif nil == updatedVal {\n\t\t\terr = fmt.Errorf(\"clone attribute view text value [%s] failed\", valueID)\n\t\t\treturn\n\t\t}\n\t}\n\tif err = gulu.JSON.UnmarshalJSON(data, updatedVal); err != nil {\n\t\tlogging.LogErrorf(\"unmarshal data [%s] failed: %s\", data, err)\n\t\treturn\n\t}\n\tupdatedVal.ID = valueID\n\tupdatedVal.KeyID = keyID\n\tupdatedVal.BlockID = itemID\n\tupdatedVal.Type = valueType\n\tupdatedVal.CreatedAt = valueCreatedAt\n\tif av.KeyTypeBlock == valueType && !updatedVal.IsDetached {\n\t\tif updatedVal.Block == nil {\n\t\t\treturn nil, ErrBlockNotFound\n\t\t}\n\t\t_, tree, loadErr := getNodeByBlockID(tx, updatedVal.Block.ID)\n\t\tif loadErr != nil {","sourceCodeStart":8140,"sourceCodeEnd":8176,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view.go#L8140-L8176","documentation":"When updating an attribute view cell value of type text or block, the kernel clones the existing value and merges/validates incoming JSON against the clone so a failed validation doesn't corrupt the stored value. If val.Clone() returns nil, the kernel cannot construct the working copy and returns this formatted error including the value ID.","triggerScenarios":"Calling the cell value update API for a text or block (primary key) cell whose current value object fails to clone (nil result from Clone), i.e. the in-memory value is missing or in an unexpected state.","commonSituations":"Stale client cache: the value ID refers to a cell removed/changed by another client; corrupted .av data where the value object is incomplete; race between deleting a row and updating its cell.","solutions":["Refresh the attribute view (re-fetch it) to get current value IDs, then retry with a valid valueID","Verify the valueID exists in the target key's values before updating","Re-index or repair the .av file if the value object is corrupted (rebuild via data reindex)","Check for concurrent modification and serialize updates to the same view"],"exampleFix":"// before\nfetch(\"/api/av/setAttributeViewBlockAttr\", {body: {valueID: staleID, ...}})\n// after\nconst av = await getAttrView(avID); // re-fetch and confirm the value exists\nif (!findValue(av, valueID)) throw new Error(\"stale valueID\");\nfetch(\"/api/av/setAttributeViewBlockAttr\", {body: {valueID, ...}})","handlingStrategy":"retry","validationCode":"const exists = attrView.KeyValues.some(kv => kv.Key.Values.some(v => v.ID === valueID));\nif (!exists) throw new Error(`stale or unknown valueID: ${valueID}`);","typeGuard":null,"tryCatchPattern":"try { await setBlockAttr(op); } catch (e) { if (String(e).includes(\"clone attribute view text value\")) { await refreshAttrView(); retry(op); } else { throw e; } }","preventionTips":["Re-fetch the attribute view before updates after other clients may have changed it","Avoid holding valueIDs across long-lived sessions","Reindex the workspace if .av corruption is suspected"],"tags":["attribute-view","clone","internal"],"backgroundTag":"internal-invariant-violation","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}