{"record":{"id":"2bca2687b274bcdb","repo":"semaphoreui/semaphore","slug":"deploy-is-build-but-build-template-does-not-exist","errorCode":null,"errorMessage":"deploy is build but build_template does not exist in templates[].name","messagePattern":"deploy is build but build_template does not exist in templates\\[\\]\\.name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"services/project/restore.go","lineNumber":275,"sourceCode":"\t\treturn fmt.Errorf(\"vault_key does not exist in keys[].name\")\n\t}\n\n\tif e.Vaults != nil {\n\t\tfor _, vault := range e.Vaults {\n\t\t\tif vault.VaultKey != nil {\n\t\t\t\tif getEntryByName[BackupAccessKey](vault.VaultKey, backup.Keys) == nil {\n\t\t\t\t\treturn fmt.Errorf(\"vaults[].vaultKey does not exist in keys[].name\")\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif e.View != nil && getEntryByName[BackupView](e.View, backup.Views) == nil {\n\t\treturn fmt.Errorf(\"view does not exist in views[].name\")\n\t}\n\n\tif buildTemplate := getEntryByName[BackupTemplate](e.BuildTemplate, backup.Templates); string(e.Type) == \"deploy\" && buildTemplate == nil {\n\t\treturn fmt.Errorf(\"deploy is build but build_template does not exist in templates[].name\")\n\t}\n\n\treturn nil\n}\n\nfunc (e BackupTemplate) Restore(b *BackupDB) error {\n\tvar InventoryID *int\n\tif e.Inventory != nil {\n\t\tif k := findEntityByName[db.Inventory](e.Inventory, b.inventories); k == nil {\n\t\t\treturn fmt.Errorf(\"inventory does not exist in inventories[].name\")\n\t\t} else {\n\t\t\tid := k.GetID()\n\t\t\tInventoryID = &id\n\t\t}\n\t}\n\n\tvar EnvironmentIDs []int\n\tfor i := range e.Environments {","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/services/project/restore.go#L257-L293","documentation":"Thrown by BackupTemplate.Verify when a template has Type \"deploy\" but its BuildTemplate reference does not resolve to a name in backup.Templates. Deploy-type templates build on another template, so the referenced build template must be present in the same backup.","triggerScenarios":"Verify where string(e.Type) == \"deploy\" and getEntryByName[BackupTemplate](e.BuildTemplate, backup.Templates) == nil — exporting the deploy template without the build template it depends on, or a typo/renamed build template.","commonSituations":"Partial exports containing only deploy templates; build templates deleted after backup; renaming a build template between backup and restore; copying deploy templates across projects.","solutions":["Include the referenced build template in backup.Templates.","Update the deploy template's buildTemplate field to an existing templates[].name.","Change the template type or remove the buildTemplate reference if it should not build.","Set BuildTemplate to null if the deploy template no longer builds from another template (if allowed)."],"exampleFix":"// before\n\"templates\": [{\"name\": \"deploy-app\", \"type\": \"deploy\", \"buildTemplate\": \"build-app\"}]\n// after (add the dependency)\n\"templates\": [{\"name\": \"build-app\", \"type\": \"build\"}, {\"name\": \"deploy-app\", \"type\": \"deploy\", \"buildTemplate\": \"build-app\"}]","handlingStrategy":"validation","validationCode":"if t.Type == \"deploy\" && !templateNameExists(t.BuildTemplate, backup.Templates) {\n  return fmt.Errorf(\"deploy template %q missing build template %q\", t.Name, t.BuildTemplate)\n}","typeGuard":"func templateNameExists(name string, tmpls []BackupTemplate) bool {\n  for _, t := range tmpls {\n    if t.Name == name { return true }\n  }\n  return false\n}","tryCatchPattern":"if err := tmpl.Verify(backup); err != nil {\n  if strings.Contains(err.Error(), \"build_template does not exist\") {\n    // export the build template too, then retry\n  }\n}","preventionTips":["Always export deploy templates together with the build templates they depend on.","Model the deploy->build dependency when constructing backups programmatically.","Verify before restore so dependency gaps surface before any DB writes."],"tags":["restore","backup","referential-integrity","template","go"],"backgroundTag":"entity-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"}