{"record":{"id":"1eec4a644b5ef160","repo":"siyuan-note/siyuan","slug":"new-item-template-s-does-not-create-a-bound-blo","errorCode":null,"errorMessage":"new item template [%s] does not create a bound block","messagePattern":"new item template \\[(.+?)\\] does not create a bound block","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_new_item.go","lineNumber":118,"sourceCode":"\tcreatedAt := time.Now()\n\titemTemplate := attrView.GetNewItemTemplate(templateID)\n\tvar prunedOptions []*av.PrunedNewItemTemplateOption\n\tif \"\" != templateID && nil == itemTemplate {\n\t\treturn nil, fmt.Errorf(\"new item template [%s] not found\", templateID)\n\t}\n\tif nil == itemTemplate {\n\t\titemTemplate = &av.NewItemTemplate{TargetType: av.NewItemTargetDetached}\n\t} else {\n\t\tcloned := *attrView\n\t\tprunedOptions = cloned.PruneInvalidNewItemTemplateFieldValues()\n\t\tif err = cloned.SetNewItemTemplates(&av.NewItemTemplatesConfig{Templates: []*av.NewItemTemplate{itemTemplate}}); nil != err {\n\t\t\treturn nil, err\n\t\t}\n\t\tattrView = &cloned\n\t\titemTemplate = cloned.NewItemTemplates[0]\n\t}\n\tif nil != document && av.NewItemTargetDocument != itemTemplate.TargetType {\n\t\treturn nil, fmt.Errorf(\"new item template [%s] does not create a bound block\", templateID)\n\t}\n\tprimaryFallback := \"\"\n\tif nil != document {\n\t\tprimaryFallback = document.Title\n\t}\n\tpreview, err := resolveAttributeViewNewItemTemplateWithFallback(blockID, itemTemplate, createdAt, primaryFallback)\n\tif nil != err {\n\t\treturn nil, err\n\t}\n\tfor _, prunedOption := range prunedOptions {\n\t\tif templateID == prunedOption.TemplateID {\n\t\t\tpreview.Warnings = append(preview.Warnings, fmt.Sprintf(Conf.Language(353),\n\t\t\t\tprunedOption.KeyID, strings.Join(prunedOption.Values, \", \")))\n\t\t}\n\t}\n\n\tdbTree, err := LoadTreeByBlockID(blockID)\n\tif nil != err {","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_new_item.go#L100-L136","documentation":"createAttributeViewItem validates that a template used with a Markdown document payload targets documents. When CreateAttributeViewItemWithMarkdown (or the internal createAttributeViewItem) is called with a non-nil `document`, but the resolved new-item template's TargetType is not av.NewItemTargetDocument, the API cannot attach the supplied Markdown to a bound block and fails fast with this error. It is a caller-side template/payload mismatch guard, not a data corruption error.","triggerScenarios":"Call CreateAttributeViewItemWithMarkdown (kernel API /api/attr/createAttributeViewItemWithMarkdown) with a document payload while the templateID resolves to a template whose TargetType is NewItemTargetDetached (or any non-document target). Also occurs when the stored template in the attribute view was edited/changed to a non-document target after the client decided to send Markdown.","commonSituations":"A plugin or client cached a template ID that was later reconfigured in the database's 'new item template' settings to a detached item; UI code that always sends Markdown for every template; version drift where older templates created before the document-target feature default to detached.","solutions":["Open the database's new-item template settings and change the referenced template's target type to 'document' (NewItemTargetDocument), or pick a template ID that already targets documents","If a bound block is not needed, call CreateAttributeViewItem instead of CreateAttributeViewItemWithMarkdown and pass no document payload","Before calling, resolve the template (attrView.GetNewItemTemplate(templateID)) and assert TargetType == av.NewItemTargetDocument"],"exampleFix":"// before\nresult, err := model.CreateAttributeViewItemWithMarkdown(avID, blockID, viewID, detachedTemplateID, \"\", \"\", doc)\n// after\nif tpl := attrView.GetNewItemTemplate(detachedTemplateID); tpl != nil && tpl.TargetType != av.NewItemTargetDocument {\n    result, err = model.CreateAttributeViewItem(avID, blockID, viewID, detachedTemplateID, \"\", \"\")\n} else {\n    result, err = model.CreateAttributeViewItemWithMarkdown(avID, blockID, viewID, detachedTemplateID, \"\", \"\", doc)\n}","handlingStrategy":"validation","validationCode":"if tpl := attrView.GetNewItemTemplate(templateID); doc != nil && tpl != nil && tpl.TargetType != av.NewItemTargetDocument {\n    return fmt.Errorf(\"template %s cannot accept a document payload\", templateID)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always resolve the template and check TargetType before sending a Markdown document payload","Keep template IDs in client config synchronized with the database's template definitions","Use CreateAttributeViewItem (no document) for detached templates"],"tags":["attribute-view","template-mismatch","go-kernel"],"backgroundTag":"incompatible-source-type","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"}