{"record":{"id":"2abf76d2ae76cf71","repo":"siyuan-note/siyuan","slug":"duplicated-new-item-template-id-s","errorCode":null,"errorMessage":"duplicated new item template id [%s]","messagePattern":"duplicated new item template id \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":70,"sourceCode":"\t\t\treturn errors.New(\"clone new item template failed\")\n\t\t}\n\t\titemTemplate.Name = strings.TrimSpace(itemTemplate.Name)\n\t\titemTemplate.Icon = strings.TrimSpace(itemTemplate.Icon)\n\t\tif filteredIcon, valid := util.FilterIconValue(itemTemplate.Icon); valid {\n\t\t\titemTemplate.Icon = filteredIcon\n\t\t} else {\n\t\t\t// 非法图标值置空，防止存储可执行标记\n\t\t\t// https://github.com/siyuan-note/siyuan/security/advisories/GHSA-vx5w-qrvp-mmcq\n\t\t\titemTemplate.Icon = \"\"\n\t\t}\n\t\tif \"\" == itemTemplate.Name {\n\t\t\treturn errors.New(\"new item template name is empty\")\n\t\t}\n\t\tif !ast.IsNodeIDPattern(itemTemplate.ID) {\n\t\t\treturn fmt.Errorf(\"invalid new item template id [%s]\", itemTemplate.ID)\n\t\t}\n\t\tif templateIDs[itemTemplate.ID] {\n\t\t\treturn fmt.Errorf(\"duplicated new item template id [%s]\", itemTemplate.ID)\n\t\t}\n\t\ttemplateIDs[itemTemplate.ID] = true\n\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)","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L52-L88","documentation":"Template IDs within one NewItemTemplatesConfig must be unique; SetNewItemTemplates tracks seen IDs in templateIDs map and rejects duplicates with this error naming the repeated ID. Duplicate IDs would make default-template resolution and lookup ambiguous.","triggerScenarios":"Submitting a config where two or more templates share the same ID — commonly from copying an existing template entry without generating a new ID.","commonSituations":"Duplicating a template row in the settings UI; merging configs from two sources; round-tripping a config where a new template reused the old ID.","solutions":["Assign a distinct valid node ID to every template in the config.","Deduplicate by ID before calling SetNewItemTemplates (keep the last or first occurrence deliberately).","When cloning a template for editing, regenerate its ID on save."],"exampleFix":"// before\n{id: \"20240918120000-abcdef0123456789\", name: \"A\"}, {id: \"20240918120000-abcdef0123456789\", name: \"B\"}\n// after\n{id: \"20240918120000-abcdef0123456789\", name: \"A\"}, {id: \"20240918120001-0123456789abcdef\", name: \"B\"}","handlingStrategy":"validation","validationCode":"seen := map[string]bool{}\nfor _, t := range cfg.Templates {\n\tif seen[t.ID] { return fmt.Errorf(\"duplicate template id %s\", t.ID) }\n\tseen[t.ID] = true\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Regenerate the ID whenever duplicating a template","Deduplicate configs before merging sources","Enforce uniqueness in the settings UI at edit time"],"tags":["attribute-view","duplicate","validation","go"],"backgroundTag":"conflicting-config-options","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"}