{"record":{"id":"188751a30d04a39e","repo":"semaphoreui/semaphore","slug":"template-does-not-exist-in-templates-name","errorCode":null,"errorMessage":"template does not exist in templates[].name","messagePattern":"template does not exist in templates\\[\\]\\.name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"services/project/restore.go","lineNumber":107,"sourceCode":"\tnewView, err := b.store.CreateView(v)\n\tif err != nil {\n\t\treturn err\n\t}\n\tb.views = append(b.views, newView)\n\treturn nil\n}\n\nfunc (e BackupSchedule) Verify(backup *BackupFormat) error {\n\treturn verifyDuplicate[BackupSchedule](e.Name, backup.Schedules)\n}\n\nfunc (e BackupSchedule) Restore(b *BackupDB) error {\n\tv := e.Schedule\n\tv.ProjectID = b.meta.ID\n\n\ttpl := findEntityByName[db.Template](&e.Template, b.templates)\n\tif tpl == nil {\n\t\treturn fmt.Errorf(\"template does not exist in templates[].name\")\n\t}\n\tv.TemplateID = tpl.ID\n\n\tif e.CheckableRepository != nil {\n\t\trepo := findEntityByName[db.Repository](e.CheckableRepository, b.repositories)\n\t\tif repo == nil {\n\t\t\treturn fmt.Errorf(\"repo does not exist in repositories[].name\")\n\t\t}\n\t\tv.RepositoryID = &repo.ID\n\t}\n\n\tif e.TaskParams != nil {\n\t\tinv := findEntityByName[db.Inventory](e.TaskParams.InventoryName, b.inventories)\n\t\tif inv != nil {\n\t\t\tv.TaskParams.InventoryID = &inv.ID\n\t\t}\n\t}\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/services/project/restore.go#L89-L125","documentation":"BackupSchedule.Restore resolves the schedule's referenced template by name within the restored project's templates using findEntityByName. If no template with the referenced name exists in the backup's templates[] array, restore aborts with this error to avoid creating a schedule pointing at a nonexistent template.","triggerScenarios":"Restoring a project backup where a schedule's template name does not match any entry in templates[].name — e.g. the template was deleted, renamed, or the backup arrays were edited separately.","commonSituations":"Partial backups that omitted templates[]; renamed templates after export; cross-project restores where the schedule references a template from another project; manual JSON cleanup removing a 'unused' template still referenced by a schedule.","solutions":["Add a template entry with the exact missing name to templates[] in the backup.","Rename the schedule's template reference to match an existing templates[].name entry.","Remove or comment out the schedule if it is no longer needed.","Re-export a full backup that includes both templates and schedules from the source project."],"exampleFix":"// before\n\"schedules\": [{\"template\": \"nightly-build\"}], \"templates\": []\n// after\n\"templates\": [{\"name\": \"nightly-build\", ...}], \"schedules\": [{\"template\": \"nightly-build\"}]","handlingStrategy":"validation","validationCode":"func scheduleTemplateExists(b BackupFormat) error {\n    for _, s := range b.Schedules {\n        if getEntryByName[BackupTemplate](s.Template, b.Templates) == nil {\n            return fmt.Errorf(\"schedule references missing template %q\", s.Template)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := backup.Verify(); err != nil {\n    if strings.Contains(err.Error(), \"template does not exist\") {\n        // add the template or fix the schedule reference, then retry\n    }\n    return err\n}","preventionTips":["Always export full project backups including templates and schedules together.","Run Verify before Restore in CI/CD pipelines.","Update schedule references whenever templates are renamed or deleted."],"tags":["backup-restore","referential-integrity","missing-reference"],"backgroundTag":"resource-not-found","analyzedSha":"1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa","analyzedAt":"2026-09-07T11:00:33.293Z","contentChangedAt":"2026-09-07T11:00:33.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}