{"record":{"id":"dd79f1a922a3434b","repo":"semaphoreui/semaphore","slug":"duplicate-key-s","errorCode":null,"errorMessage":"duplicate key %s","messagePattern":"duplicate key (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"services/export/Exporter.go","lineNumber":258,"sourceCode":"\t\t}\n\t}\n\treturn keys, nil\n}\n\nfunc (t *ValueMap[T]) appendValues(values []T, scope string) error {\n\treturn t.appendValuesAndCheck(values, scope, t.uniqueKeys)\n}\n\nfunc (t *ValueMap[T]) appendValuesAndCheck(values []T, scope string, checkDuplicates bool) error {\n\tif t.values == nil {\n\t\tt.keyScopeMap = make(map[string]bool)\n\t\tt.values = make([]EntityObject[T], 0)\n\t}\n\tfor _, v := range values {\n\t\tif checkDuplicates {\n\t\t\t_, ok := t.keyScopeMap[scope+v.GetDbKey()]\n\t\t\tif ok {\n\t\t\t\treturn fmt.Errorf(\"duplicate key %s\", v.GetDbKey())\n\t\t\t}\n\t\t\tt.keyScopeMap[scope+v.GetDbKey()] = true\n\t\t}\n\t\tt.values = append(t.values, EntityObject[T]{value: v, scope: scope})\n\t}\n\treturn nil\n}\n\nfunc (t *ValueMap[T]) exportDependsOn() []string {\n\treturn []string{}\n}\n\nfunc (t *ValueMap[T]) importDependsOn() []string {\n\treturn []string{}\n}\n\nfunc (t *ValueMap[T]) onError(err string) {\n\tif t.errs == nil {","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/services/export/Exporter.go#L240-L276","documentation":"ValueMap.appendValuesAndCheck detects duplicate entity keys when checkDuplicates is enabled. Two objects of the same type sharing the same scope+DbKey indicate corrupt or overlapping export data, so appending is aborted.","triggerScenarios":"Calling appendValues (which uses appendValuesAndCheck with duplicate checking) with a batch containing two EntityObject values whose GetDbKey() is identical within the same scope — e.g. loading the same entity twice or a store query returning duplicates.","commonSituations":"Database rows with duplicated logical keys; loading the same export file or entity set twice into one chain; buggy custom exporter emitting the same object multiple times.","solutions":["Deduplicate the values slice before appending (key by scope+GetDbKey)","Verify the source store does not contain duplicate rows for the entity's DB key","Reset or recreate the ValueMap if a prior load already inserted the same entities"],"exampleFix":"// before\nchain.appendValues(values) // errors on second occurrence of key\n// after\nseen := map[EntityKey]bool{}\nfor _, v := range values {\n    if !seen[v.GetDbKey()] {\n        seen[v.GetDbKey()] = true\n        chain.appendValues([]T{v})\n    }\n}","handlingStrategy":"try-catch","validationCode":"seen := map[string]bool{}\nfor _, v := range values {\n    k := scope + v.GetDbKey()\n    if seen[k] { return fmt.Errorf(\"pre-check: duplicate %s\", k) }\n    seen[k] = true\n}","typeGuard":null,"tryCatchPattern":"err := valueMap.appendValues(values)\nif err != nil {\n    var dup string\n    if n, _ := fmt.Sscanf(err.Error(), \"duplicate key %s\", &dup); n == 1 {\n        log.Warnf(\"skipping duplicate %s\", dup)\n        return nil\n    }\n    return err\n}","preventionTips":["Deduplicate query results before loading into the ValueMap","Never load the same export source twice into one chain","Enforce unique DB keys at the source schema level"],"tags":["go","export","import","duplicate-data"],"backgroundTag":"duplicate-key","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"}