{"record":{"id":"6c78c03e31d14a3a","repo":"siyuan-note/siyuan","slug":"current-document-is-not-bound-to-the-context-filter-target","errorCode":null,"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/9f775e8a12daef8255556097396f9b2739078892/kernel/av/context_filter.go#L14-L50","documentation":"ErrAttributeViewContextNotBound signals that a context filter is configured on a database block, but the current document has not been resolved to any row IDs in the target database (filterContext.CurrentDocumentItemIDs is empty). The library refuses to proceed because context filtering requires the carrying document to actually map to database items. Callers like GetAttrViewAddingBlockDefaultValues and createAttributeViewItem raise it before computing defaults or creating items.","triggerScenarios":"Calling GetAttrViewAddingBlockDefaultValues or createAttributeViewItem (kernel/model/attribute_view.go:368, :6246) with a non-nil filter context whose CurrentDocumentItemIDs has zero entries — i.e. the block embedding the database is not itself a row (item) of the filtered database.","commonSituations":"Embedding an attribute-view block in a document that is not bound to the database as a row; using a context-filtered database on a detached document; copying a filtered database block into a plain document without a carrier block.","solutions":["Bind the current document/block to the database by adding it as a row so CurrentDocumentItemIDs is populated before the call.","Check filterContext.CurrentDocumentItemIDs length before calling and skip or surface a user-facing hint when it is empty.","Remove the context filter from the database block if cross-document unbound usage is intended."],"exampleFix":"// before\nitem, err := createAttributeViewItem(view, filterContext)\n// after\nif nil != filterContext && 1 > len(filterContext.CurrentDocumentItemIDs) {\n\treturn errors.New(\"block is not a row of the filtered database; bind it first\")\n}\nitem, err := createAttributeViewItem(view, filterContext)","handlingStrategy":"validation","validationCode":"if nil != filterContext && len(filterContext.CurrentDocumentItemIDs) == 0 {\n\t// refuse to call; surface guidance to bind the document\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use context-filtered database blocks in documents that are actual rows of the database","Check CurrentDocumentItemIDs before invoking default-value or item-creation APIs","Strip context filters when moving database blocks into unbound documents"],"tags":["database","attribute-view","context-filter","go"],"backgroundTag":"empty-result-set","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"}