{"record":{"id":"8b80dd7f1c095a23","repo":"siyuan-note/siyuan","slug":"attribute-view-order-changed-retry-the-drag","errorCode":null,"errorMessage":"attribute view order changed; retry the drag","messagePattern":"attribute view order changed; retry the drag","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/attribute_view_row_sort.go","lineNumber":236,"sourceCode":"\t\t\tret = append(ret, id)\n\t\t\tseen[id] = true\n\t\t}\n\t}\n\treturn ret\n}\n\nfunc applyAttributeViewRowOrder(attrView *av.AttributeView, view *av.View, data any) error {\n\tencoded, err := gulu.JSON.MarshalJSON(data)\n\tif nil != err {\n\t\treturn err\n\t}\n\tvar change attributeViewRowOrderChange\n\tif err = gulu.JSON.UnmarshalJSON(encoded, &change); nil != err {\n\t\treturn err\n\t}\n\tif nil == change.RowOrder || nil == change.Expected ||\n\t\t!reflect.DeepEqual(getAttributeViewRowOrder(view), change.Expected) {\n\t\treturn errors.New(\"attribute view order changed; retry the drag\")\n\t}\n\tif len(change.RowOrder.Groups) != len(view.Groups) {\n\t\treturn errors.New(\"attribute view groups changed; retry the drag\")\n\t}\n\tfor _, group := range view.Groups {\n\t\tif _, ok := change.RowOrder.Groups[group.ID]; !ok {\n\t\t\treturn errors.New(\"attribute view group not found\")\n\t\t}\n\t}\n\tif nil != change.ValidateGroup && len(change.RowOrder.Sorts) > 0 {\n\t\t// 预览之后字段值可能变化，提交时再次校验，不能悄悄接受冲突的落点。\n\t\tcopyView, copyErr := cloneAttributeViewRowSort(attrView)\n\t\tif nil != copyErr {\n\t\t\treturn copyErr\n\t\t}\n\t\tcandidate := copyView.GetView(view.ID)\n\t\tsetAttributeViewRowOrder(candidate, change.RowOrder)\n\t\tcollections, renderErr := renderAttributeViewRowSortCollections(copyView, candidate, false)","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_row_sort.go#L218-L254","documentation":"applyAttributeViewRowOrder commits a drag's new row order using optimistic concurrency: the client sends both the intended RowOrder and the Expected order snapshot it based its drag on. Before applying, the kernel deep-compares the view's actual current row order against Expected. Any mismatch — including a missing RowOrder or Expected — means the view changed since the preview, and the commit is rejected with a retry hint rather than silently overwriting concurrent changes.","triggerScenarios":"Submitting a row-order change whose Expected snapshot no longer matches the live view: another client modified rows in the meantime, sort values changed so the rendered order differs, or the payload omits rowOrder/expected fields entirely (nil pointers also trigger this error).","commonSituations":"Two windows open on the same database dragging rows concurrently; a long-lived preview followed by a background change (e.g. sync or another process updating cell values); a plugin constructing the payload but forgetting the expected field.","solutions":["Re-fetch the attribute view, recompute both expected and rowOrder from the fresh state, and re-apply the drag.","Include non-nil rowOrder and expected objects in the payload — missing fields are treated as a stale commit.","Resolve concurrent edits first (close other editors or wait for sync to settle), then retry.","Keep the time between preview and commit short to minimize the chance of intervening changes."],"exampleFix":"// before\napplyRowOrder(avID, { rowOrder: newOrder }) // missing expected\n// after\napplyRowOrder(avID, { rowOrder: newOrder, expected: getCurrentRowOrderSnapshot(view) })","handlingStrategy":"retry","validationCode":"if (!payload.rowOrder || !payload.expected) {\n  throw new Error(\"rowOrder and expected are required for optimistic row-order commit\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await applyAttributeViewRowOrder(payload);\n} catch (e) {\n  if (String(e.msg).includes(\"order changed; retry\")) {\n    const fresh = await fetchAttributeView(avID);\n    payload.expected = snapshotRowOrder(fresh);\n    // redo the drag/reorder against the fresh state\n  }\n}","preventionTips":["Always send the expected snapshot captured at preview time, kept non-nil","Minimize the window between preview and commit on shared databases"],"tags":["go","attribute-view","concurrency","optimistic-locking"],"backgroundTag":"invalid-state-transition","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"}