{"record":{"id":"52e0c99b12790e6f","repo":"crowdsecurity/crowdsec","slug":"unable-to-delete-allowlist-items-w","errorCode":null,"errorMessage":"unable to delete allowlist items: %w","messagePattern":"unable to delete allowlist items: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/allowlists.go","lineNumber":45,"sourceCode":"\t\tSetFromConsole(fromConsole).\n\t\tSetDescription(description).\n\t\tSetAllowlistID(allowlistID).\n\t\tSave(ctx)\n\tif err != nil {\n\t\tif sqlgraph.IsUniqueConstraintError(err) {\n\t\t\treturn nil, fmt.Errorf(\"allowlist '%s' already exists\", name)\n\t\t}\n\n\t\treturn nil, fmt.Errorf(\"unable to create allowlist: %w\", err)\n\t}\n\n\treturn allowlist, nil\n}\n\nfunc (c *Client) DeleteAllowList(ctx context.Context, name string, fromConsole bool) error {\n\tnbDeleted, err := c.Ent.AllowListItem.Delete().Where(allowlistitem.HasAllowlistWith(allowlist.NameEQ(name), allowlist.FromConsoleEQ(fromConsole))).Exec(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to delete allowlist items: %w\", err)\n\t}\n\n\tc.Log.Debugf(\"deleted %d items from allowlist %s\", nbDeleted, name)\n\n\tnbDeleted, err = c.Ent.AllowList.\n\t\tDelete().\n\t\tWhere(allowlist.NameEQ(name), allowlist.FromConsoleEQ(fromConsole)).\n\t\tExec(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to delete allowlist: %w\", err)\n\t}\n\n\tif nbDeleted == 0 {\n\t\treturn fmt.Errorf(\"allowlist %s not found\", name)\n\t}\n\n\treturn nil\n}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/allowlists.go#L27-L63","documentation":"DeleteAllowList first removes the allowlist's items, then the allowlist itself. This error means the AllowListItem DELETE (filtered by allowlist name and fromConsole flag) failed, so nothing was deleted and the whole operation aborted. The raw DB error is wrapped.","triggerScenarios":"c.DeleteAllowList(ctx, name, fromConsole) where AllowListItem.Delete().Where(allowlistitem.HasAllowlistWith(...)) fails — DB down, permission, lock, or context cancellation.","commonSituations":"cscli allowlist delete while the DB is under heavy write load; DB connection dropped; DB user lacking DELETE on allowlist_items.","solutions":["Inspect the wrapped database error for the root cause","Verify DB connectivity and DELETE grants on the allowlist_items table","Retry the delete","Check for lock contention with concurrent allowlist edits"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"exists, err := client.Ent.AllowList.Query().Where(allowlist.NameEQ(name), allowlist.FromConsoleEQ(fromConsole)).Exist(ctx)\nif err != nil || !exists { /* allowlist absent: skip */ }","typeGuard":null,"tryCatchPattern":"err := client.DeleteAllowList(ctx, name, false)\nif err != nil {\n    // raw DB error is wrapped; log it and check connectivity/grants\n    return err\n}","preventionTips":["Confirm the allowlist exists and the fromConsole flag matches before deleting","Grant DELETE on allowlist_items to the DB user","Retry on transient DB failures","Avoid deleting allowlists while console sync is writing items"],"tags":["database","delete","allowlist"],"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"}