Skip to content

Commit

Permalink
fix(schema): schema validation to handle potential nil field case (#…
Browse files Browse the repository at this point in the history
…13861)

Adjusted schema validation logic to account for `nil` field scenario, 
ensuring proper handling of fields to prevent errors.

Fix:[FTI-6336](https://konghq.atlassian.net/browse/FTI-6336)

---------

Signed-off-by: tzssangglass <tzssangglass@gmail.com>
Co-authored-by: Keery Nie <windmgc@gmail.com>
  • Loading branch information
tzssangglass and windmgc authored Nov 13, 2024
1 parent a6dceee commit 9ce1b9d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "Fixed a 500 error triggered by unhandled nil fields during schema validation."
type: bugfix
scope: Core
2 changes: 1 addition & 1 deletion kong/db/schema/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ local function run_entity_check(self, name, input, arg, full_check, errors)

-- Don't run if any of the values is a reference in a referenceable field
local field = get_schema_field(self, fname)
if field.type == "string" and field.referenceable and is_reference(value) then
if field and field.type == "string" and field.referenceable and is_reference(value) then
return
end
end
Expand Down
31 changes: 31 additions & 0 deletions spec/01-unit/01-db/01-schema/06-routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1800,3 +1800,34 @@ describe("routes schema (flavor = expressions)", function()
end
end)
end)


describe("routes schema (flavor = traditional_compatible)", function()
local a_valid_uuid = "cbb297c0-a956-486d-ad1d-f9b42df9465a"
local another_uuid = "64a8670b-900f-44e7-a900-6ec7ef5aa4d3"

reload_flavor("traditional_compatible")
setup_global_env()

it("validates a route with only expression field", function()
local route = {
id = a_valid_uuid,
name = "my_route",
protocols = { "http" },
hosts = { "example.com" },
expression = [[(http.method == "GET")]],
priority = 100,
service = { id = another_uuid },
}
route = Routes:process_auto_fields(route, "insert")
assert.truthy(route.created_at)
assert.truthy(route.updated_at)
assert.same(route.created_at, route.updated_at)
local ok, errs = Routes:validate(route)
assert.falsy(ok)
assert.same({
["expression"] = 'unknown field',
["priority"] = 'unknown field'
}, errs)
end)
end)

1 comment on commit 9ce1b9d

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:9ce1b9d2a656632efa660aa5a572322688e946f8
Artifacts available https://github.com/Kong/kong/actions/runs/11810637754

Please sign in to comment.