diff --git a/kong/api/crud_helpers.lua b/kong/api/crud_helpers.lua index 0f05e030cc62..befdaeea41f9 100644 --- a/kong/api/crud_helpers.lua +++ b/kong/api/crud_helpers.lua @@ -47,6 +47,12 @@ function _M.paginated_set(self, dao_collection) self.params.size = nil self.params.offset = nil + for k, _ in pairs(self.params) do + if not dao_collection._schema.fields[k] then + self.params[k] = nil + end + end + local data, err = dao_collection:find_by_keys(self.params, size, offset) if err then return app_helpers.yield_error(err) diff --git a/spec/integration/admin_api/consumers_routes_spec.lua b/spec/integration/admin_api/consumers_routes_spec.lua index 9929b98d32c6..e0a067928f31 100644 --- a/spec/integration/admin_api/consumers_routes_spec.lua +++ b/spec/integration/admin_api/consumers_routes_spec.lua @@ -169,6 +169,14 @@ describe("Admin API", function() assert.falsy(body_page_3.next) assert.not_same(body_page_2, body_page_3) end) + it("should not throw an error when filtering with a random field", function() + local response, status = http_client.get(BASE_URL, {hello="world"}) + assert.equal(200, status) + local body = json.decode(response) + assert.truthy(body.data) + assert.equal(10, table.getn(body.data)) + assert.equal(10, body.total) + end) end) describe("/consumers/:consumer", function()