{"record":{"id":"6b327305033dc905","repo":"crowdsecurity/crowdsec","slug":"unable-to-update-allowlist-w","errorCode":null,"errorMessage":"unable to update allowlist: %w","messagePattern":"unable to update allowlist: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/allowlists.go","lineNumber":212,"sourceCode":"\tc.Log.Tracef(\"values: %v\", values)\n\n\tnbDeleted, err := c.Ent.AllowListItem.Delete().Where(\n\t\tallowlistitem.HasAllowlistWith(allowlist.IDEQ(list.ID)),\n\t\tallowlistitem.ValueIn(values...),\n\t).Exec(ctx)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"unable to remove values from allowlist: %w\", err)\n\t}\n\n\treturn nbDeleted, nil\n}\n\nfunc (c *Client) UpdateAllowlistMeta(ctx context.Context, allowlistID string, name string, description string) error {\n\tc.Log.Debugf(\"updating allowlist %s meta\", name)\n\n\terr := c.Ent.AllowList.Update().Where(allowlist.AllowlistIDEQ(allowlistID)).SetName(name).SetDescription(description).Exec(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to update allowlist: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (c *Client) ReplaceAllowlist(ctx context.Context, list *ent.AllowList, items []*models.AllowlistItem, fromConsole bool) (int, error) {\n\tc.Log.Debugf(\"replacing values in allowlist %s\", list.Name)\n\tc.Log.Tracef(\"items: %+v\", items)\n\n\t_, err := c.Ent.AllowListItem.Delete().Where(allowlistitem.HasAllowlistWith(allowlist.IDEQ(list.ID))).Exec(ctx)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"unable to delete allowlist contents: %w\", err)\n\t}\n\n\tadded, err := c.AddToAllowlist(ctx, list, items)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"unable to add values to allowlist: %w\", err)\n\t}","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/allowlists.go#L194-L230","documentation":"UpdateAllowlistMeta issues an ent Update setting name and description on the allowlist matched by allowlist_id. Any Exec failure — driver error, unique constraint on the new name colliding with another allowlist, cancelled context — is wrapped as 'unable to update allowlist: %w'.","triggerScenarios":"updateOneAllowlist calling Client.UpdateAllowlistMeta when the DB write fails; notably a unique-name constraint violation if the new name already exists on another allowlist row.","commonSituations":"Renaming an allowlist to a name already taken (name is unique); DB unreachable during a console sync; SQLite lock contention during concurrent LAPI requests.","solutions":["Check the wrapped error for a unique-constraint message; pick a different name if so","Verify DB connectivity and that the allowlists table schema is current","Resolve lock contention or retry after transient DB issues","Ensure the allowlistID passed actually exists (update of a missing ID silently affects 0 rows rather than erroring here)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"lists, err := client.ListAllowLists(ctx, false)\nif err != nil { return err }\nfor _, l := range lists {\n    if l.Name == newName && l.AllowlistID != allowlistID {\n        return fmt.Errorf(\"name %q already used by allowlist %s\", newName, l.AllowlistID)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := client.UpdateAllowlistMeta(ctx, id, name, desc); err != nil {\n    if strings.Contains(err.Error(), \"UNIQUE\") || strings.Contains(err.Error(), \"duplicate\") {\n        return fmt.Errorf(\"name %q already taken\", name)\n    }\n    return err\n}","preventionTips":["Uniqueness-check the new name before renaming","Confirm the allowlistID exists (0-row updates do not error here)","Keep DB connectivity healthy during console sync operations"],"tags":["database","allowlist","update","unique-constraint"],"backgroundTag":"database-write-failed","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}