{"record":{"id":"00c574bfd45dd108","repo":"siyuan-note/siyuan","slug":"errattributeviewcontextnotbound","errorCode":"ErrAttributeViewContextNotBound","errorMessage":"current document is not bound to the context filter target database","messagePattern":"current document is not bound to the context filter target database","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/context_filter.go","lineNumber":32,"sourceCode":"// You should have received a copy of the GNU Affero General Public License\n// along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\npackage av\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"strings\"\n)\n\nconst AttributeViewContextFilterSpec = 1\n\nvar (\n\tErrInvalidAttributeViewContextFilter = errors.New(\"invalid attribute view context filter\")\n\tErrAttributeViewContextNotBound      = errors.New(\"current document is not bound to the context filter target database\")\n)\n\n// AttributeViewContextFilter 描述物理数据库块独有的上下文筛选配置。\ntype AttributeViewContextFilter struct {\n\tSpec  int    `json:\"spec\"`\n\tKeyID string `json:\"keyID\"`\n}\n\n// AttributeViewContextFilterField 描述可用于物理数据库块上下文筛选的关联字段。\ntype AttributeViewContextFilterField struct {\n\tID         string `json:\"id\"`\n\tName       string `json:\"name\"`\n\tIcon       string `json:\"icon\"`\n\tTargetAvID string `json:\"targetAvID\"`\n}\n\n// FilterContext 保存一次数据库块渲染所需的上下文筛选值，不参与持久化。\ntype FilterContext struct {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/av/context_filter.go#L14-L50","documentation":"Sentinel error ErrAttributeViewContextNotBound means the current document resolved a context filter but no rows (CurrentDocumentItemIDs is empty) were bound to it — the document is not actually linked to the target database the filter points at. Callers refuse to create or default-fill attribute view items in this state.","triggerScenarios":"GetAttrViewAddingBlockDefaultValues or createAttributeViewItem with a filterContext whose CurrentDocumentItemIDs length is 0; TestResolveAttributeViewContextFilterMapsCarrierDocument checks the same condition.","commonSituations":"A document that previously embedded a database row binding was edited/unlinked; the context filter key exists but the document block is no longer a row of that database; copying a doc without its database binding.","solutions":["Re-bind the document to the target database (insert the block as a database row) so CurrentDocumentItemIDs is populated","Remove the stale context filter from the document if the binding is no longer wanted","Verify the filter's keyID targets the database the document actually belongs to"],"exampleFix":"// before\n// filterContext exists but document has no bound rows -> err returned\n// after\n// add the block as a row in the target database so CurrentDocumentItemIDs contains its item ID\n","handlingStrategy":"type-guard","validationCode":"if (filterContext && (!filterContext.currentDocumentItemIDs || filterContext.currentDocumentItemIDs.length === 0)) { rebindDocumentToDatabase(doc, db); }","typeGuard":"function isBoundToDocument(fc) { return fc != null && Array.isArray(fc.currentDocumentItemIDs) && fc.currentDocumentItemIDs.length > 0; }","tryCatchPattern":"try { return createItem(docID); } catch (e) { if (errors.is(e, ErrAttributeViewContextNotBound)) { await rebindDocument(docID); return createItem(docID); } throw e; }","preventionTips":["Re-check document-to-database binding after copy/move operations","Remove stale context filters when unbinding documents","Verify keyID targets the database the document is a row of"],"tags":["attribute-view","context-filter","state-error"],"backgroundTag":"entity-not-found","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}