{"record":{"id":"79a7fabb093df6e5","repo":"siyuan-note/siyuan","slug":"attribute-view-sort-values-changed-retry-the-drag","errorCode":null,"errorMessage":"attribute view sort values changed; retry the drag","messagePattern":"attribute view sort values changed; retry the drag","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_row_sort.go","lineNumber":265,"sourceCode":"\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)\n\t\tif nil != renderErr {\n\t\t\treturn renderErr\n\t\t}\n\t\tcollection := collections[*change.ValidateGroup]\n\t\tif nil == collection {\n\t\t\treturn av.ErrViewNotFound\n\t\t}\n\t\tordered := attributeViewRowSortIDs(collection.GetItems())\n\t\tav.Sort(collection.(av.Viewable), copyView)\n\t\tif !slices.Equal(ordered, attributeViewRowSortIDs(collection.GetItems())) {\n\t\t\treturn errors.New(\"attribute view sort values changed; retry the drag\")\n\t\t}\n\t}\n\tsetAttributeViewRowOrder(view, change.RowOrder)\n\treturn nil\n}\n\nfunc isAttributeViewRowOrderOperation(data any) bool {\n\tswitch value := data.(type) {\n\tcase *attributeViewRowOrderChange:\n\t\treturn nil != value\n\tcase map[string]any:\n\t\t_, ok := value[\"rowOrder\"]\n\t\treturn ok\n\t}\n\treturn false\n}\n\nfunc setAttributeViewRowOrder(view *av.View, order *attributeViewRowOrder) {","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_row_sort.go#L247-L283","documentation":"applyAttributeViewRowOrder revalidates the submitted row sort at commit time: it clones the view, applies av.Sort on the cloned collection, and compares item order before/after. If sorting by current field values would reorder items relative to the order captured when the drag preview was made, the values have changed in the meantime and the mutation is rejected with this error instead of silently persisting a conflicting drop position.","triggerScenarios":"Calling sortAttributeViewRow with change.ValidateGroup set and RowOrder.Sorts non-empty, where the rows' sort-field values changed between preview and submission so that applying the sort produces a different item sequence than the submitted RowOrder.","commonSituations":"A user or a sync/automation edited a cell in a sort-relevant column while a drag was in progress; collaborative or background updates landed between the preview computation and the commit; a long-delayed drag submission against an active sort.","solutions":["Retry the drag: recompute the preview and resubmit sortAttributeViewRow against the refreshed view","If values changed intentionally, let the active sort reapply (or clear the view sort) before performing the drag","Avoid holding drag state across long delays; commit promptly after the user drops"],"exampleFix":"// before\napplyRowOrder(change) // stale preview, values changed\n// after\nerr := sortAttributeViewRow(change) // returns \"...retry the drag\"\nif err != nil {\n    change = recomputePreview(attrView, dragInfo) // refresh then retry\n    err = sortAttributeViewRow(change)\n}","handlingStrategy":"retry","validationCode":"// preview, then submit quickly; on server this is validated via clone+av.Sort\nconst preview = await api.getAttributeViewPreview(avID);","typeGuard":null,"tryCatchPattern":"try {\n  await api.sortAttributeViewRow(change);\n} catch (e) {\n  if (String(e.msg).includes(\"sort values changed\")) {\n    const fresh = await api.getAttributeView(avID);\n    await api.sortAttributeViewRow(recomputeRowOrder(fresh, change.Sorts));\n  }\n}","preventionTips":["Submit the row order immediately after the preview; don't hold drag state across long delays","Avoid cell edits in sort-relevant columns while a drag is pending (or let the active sort refresh first)","Treat this error as expected control flow: refresh and retry once"],"tags":["attribute-view","stale-data","sorting","retry"],"backgroundTag":"stale-data-conflict","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"}