{"record":{"id":"1e97987c99766f11","repo":"crowdsecurity/crowdsec","slug":"unable-to-delete-allowlist-w","errorCode":null,"errorMessage":"unable to delete allowlist: %w","messagePattern":"unable to delete allowlist: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/allowlists.go","lineNumber":55,"sourceCode":"\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}\n\nfunc (c *Client) DeleteAllowListByID(ctx context.Context, name string, allowlistID string, fromConsole bool) error {\n\tnbDeleted, err := c.Ent.AllowListItem.Delete().Where(allowlistitem.HasAllowlistWith(allowlist.AllowlistIDEQ(allowlistID), 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.","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/allowlists.go#L37-L73","documentation":"The second step of DeleteAllowList: deleting the allowlist row itself after its items were removed. This error means that AllowList DELETE failed; the items may already be gone while the allowlist remains. The raw DB error is wrapped.","triggerScenarios":"c.DeleteAllowList(ctx, name, fromConsole): items deleted successfully, but AllowList.Delete().Where(allowlist.NameEQ(name), allowlist.FromConsoleEQ(fromConsole)) fails — DB error, lock, or cancelled context.","commonSituations":"Connection drop between the two statements; lock contention on allowlists; DB user missing DELETE on allowlists.","solutions":["Read the wrapped DB error for the root cause","Retry DeleteAllowList — already-deleted items make it idempotent","Verify DELETE grants on the allowlists table","Note: if nbDeleted==0 afterwards, the API returns 'allowlist %s not found' — check name/fromConsole match"],"exampleFix":"// before\nerr := client.DeleteAllowList(ctx, name, false)\n// after\nif err := client.DeleteAllowList(ctx, name, false); err != nil {\n    if errors.Is(err, entdb.DeleteFail) {\n        log.Errorf(\"allowlist delete failed, check DB: %v\", err)\n    }\n}","handlingStrategy":"try-catch","validationCode":"exists, err := client.Ent.AllowList.Query().Where(allowlist.NameEQ(name), allowlist.FromConsoleEQ(fromConsole)).Exist(ctx)\nif err != nil || !exists { return nil }","typeGuard":null,"tryCatchPattern":"err := client.DeleteAllowList(ctx, name, false)\nif err != nil {\n    if strings.Contains(err.Error(), \"not found\") {\n        // name/fromConsole mismatch or already deleted\n    }\n    return err\n}","preventionTips":["Pass the correct fromConsole value — a mismatch silently yields 'not found'","Grant DELETE on allowlists to the DB user","Retry transient failures; the two-stage delete is idempotent","Verify deletion afterwards with a name query rather than assuming success"],"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"}