{"record":{"id":"03c6a98010f1502b","repo":"siyuan-note/siyuan","slug":"default-new-item-template-s-not-found","errorCode":null,"errorMessage":"default new item template [%s] not found","messagePattern":"default new item template \\[(.+?)\\] not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":91,"sourceCode":"\t\tif NewItemTargetDetached != itemTemplate.TargetType && NewItemTargetDocument != itemTemplate.TargetType {\n\t\t\treturn fmt.Errorf(\"invalid new item template target type [%s]\", itemTemplate.TargetType)\n\t\t}\n\t\tif NewItemTargetDocument != itemTemplate.TargetType {\n\t\t\titemTemplate.Icon = \"\"\n\t\t\titemTemplate.HideInFileTree = false\n\t\t}\n\t\titemTemplate.ContentTemplatePath = strings.TrimSpace(itemTemplate.ContentTemplatePath)\n\t\tif nil != itemTemplate.SaveLocation {\n\t\t\titemTemplate.SaveLocation.BoxID = strings.TrimSpace(itemTemplate.SaveLocation.BoxID)\n\t\t\titemTemplate.SaveLocation.PathTemplate = strings.TrimSpace(itemTemplate.SaveLocation.PathTemplate)\n\t\t}\n\t\tif err := av.normalizeNewItemTemplateFieldValues(itemTemplate); nil != err {\n\t\t\treturn err\n\t\t}\n\t\ttemplates = append(templates, itemTemplate)\n\t}\n\tif \"\" != defaultTemplateID && !templateIDs[defaultTemplateID] {\n\t\treturn fmt.Errorf(\"default new item template [%s] not found\", defaultTemplateID)\n\t}\n\tif 0 == len(templates) {\n\t\tav.NewItemTemplates = nil\n\t} else {\n\t\tav.NewItemTemplates = templates\n\t}\n\tav.DefaultTemplateID = defaultTemplateID\n\treturn nil\n}\n\n// GetNewItemTemplate 根据 ID 获取新增条目模板。\nfunc (av *AttributeView) GetNewItemTemplate(id string) *NewItemTemplate {\n\tfor _, itemTemplate := range av.NewItemTemplates {\n\t\tif nil != itemTemplate && itemTemplate.ID == id {\n\t\t\treturn itemTemplate\n\t\t}\n\t}\n\treturn nil","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/av/new_item_template.go#L73-L109","documentation":"config.DefaultTemplateID is non-empty but does not match any template ID actually present in config.Templates. The check runs after the per-template loop (new_item_template.go:90), so it also fires when the referenced template was skipped (nil input) or rejected earlier in the loop for a different validation failure.","triggerScenarios":"User deletes the template that is currently the default without first clearing DefaultTemplateID; a template failed earlier validation (empty name, bad ID, etc.) leaving the default pointer dangling; UI state out of sync with the backend.","commonSituations":"Delete-then-save race; client keeps a stale default ID after the user removes that template; sync applying a remote template deletion locally.","solutions":["When removing the default template, clear DefaultTemplateID (set to \"\") or repoint it to a remaining template's ID before saving.","On the client, recompute the default whenever the template list changes.","If the earlier failure is the real cause, fix the underlying validation error first so the referenced template survives the loop."],"exampleFix":"// before\nconfig.DefaultTemplateID = \"deleted-id\"\n// after\nconfig.DefaultTemplateID = \"\"","handlingStrategy":"validation","validationCode":"if config.DefaultTemplateID != \"\" {\n    found := false\n    for _, t := range config.Templates {\n        if t != nil && t.ID == config.DefaultTemplateID {\n            found = true\n            break\n        }\n    }\n    if !found {\n        return fmt.Errorf(\"default new item template [%s] not found\", config.DefaultTemplateID)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When deleting the default template, clear or repoint DefaultTemplateID in the same payload.","Recompute the default on the client whenever the template list changes.","Fix any earlier validation failure first so the referenced template survives the loop."],"tags":["av","new-item-template","default","validation","dangling-reference"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}