{"record":{"id":"9db2436db49b98a0","repo":"crowdsecurity/crowdsec","slug":"unable-to-remove-values-from-allowlist-w","errorCode":null,"errorMessage":"unable to remove values from allowlist: %w","messagePattern":"unable to remove values from allowlist: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/allowlists.go","lineNumber":201,"sourceCode":"\n\terr = txClient.Commit()\n\tif err != nil {\n\t\treturn 0, rollbackOnError(txClient, err, \"error committing transaction\")\n\t}\n\n\treturn added, nil\n}\n\nfunc (c *Client) RemoveFromAllowlist(ctx context.Context, list *ent.AllowList, values ...string) (int, error) {\n\tc.Log.Debugf(\"removing %d values from allowlist %s\", len(values), list.Name)\n\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)","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/allowlists.go#L183-L219","documentation":"RemoveFromAllowlist deletes allowlist_items matching the given allowlist ID and value list in one Exec. If the DELETE fails at the database level it is wrapped as 'unable to remove values from allowlist: %w'. A successful Exec with zero rows removed is NOT an error — removal of nonexistent values is silently a no-op returning 0.","triggerScenarios":"Client.RemoveFromAllowlist with a DB connection failure, locked database, oversized value list exceeding driver parameter limits, or cancelled context during execution.","commonSituations":"Removing many values at once hitting SQLite/MySQL placeholder limits; DB lock contention from concurrent LAPI operations; connection drop mid-delete.","solutions":["Inspect the wrapped driver error to identify the concrete failure","If removing very many values, batch them into chunks below the driver's parameter limit","Resolve SQLite lock contention or restore DB connectivity, then retry","Remember 0 returned rows is success — only handle the returned error"],"exampleFix":"// before\nclient.RemoveFromAllowlist(ctx, list, thousandsOfValues...)\n// after\nfor chunk := range slices.Chunk(values, 500) {\n    if _, err := client.RemoveFromAllowlist(ctx, list, chunk...); err != nil {\n        return err\n    }\n}","handlingStrategy":"validation","validationCode":"if len(values) == 0 { return nil } // nothing to remove; skip the query\nconst maxParams = 500\nif len(values) > maxParams { /* chunk the call */ }","typeGuard":null,"tryCatchPattern":"n, err := client.RemoveFromAllowlist(ctx, list, values...)\nif err != nil {\n    if strings.Contains(err.Error(), \"unable to remove values\") {\n        // check wrapped cause; chunk and retry if parameter-limit related\n    }\n    return err\n}\n// n==0 means values were not present — not an error","preventionTips":["Chunk large value lists to stay under driver parameter limits","Treat zero rows deleted as a normal outcome","Avoid concurrent DB writers on SQLite"],"tags":["database","allowlist","delete","sql"],"backgroundTag":"database-query-failed","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}