Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dbless): fix error data loss caused by weakly typed of function in declarative_config_flattened function #12167

Merged
merged 8 commits into from Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,3 @@
message: fix error data loss caused by weakly typed of function in declarative_config_flattened function
type: bugfix
scope: Configuration
8 changes: 7 additions & 1 deletion kong/db/errors.lua
Expand Up @@ -1033,7 +1033,13 @@ do
for i, err_t_i in drain(section_errors) do
local entity = entities[i]

if type(entity) == "table" then

-- promote error strings to `@entity` type errors
if type(err_t_i) == "string" then
err_t_i = { ["@entity"] = err_t_i }
end

if type(entity) == "table" and type(err_t_i) == "table" then
oowl marked this conversation as resolved.
Show resolved Hide resolved
add_entity_errors(entity_type, entity, err_t_i, flattened)

else
Expand Down
22 changes: 22 additions & 0 deletions spec/02-integration/04-admin_api/15-off_spec.lua
Expand Up @@ -2697,6 +2697,28 @@ R6InCcH2Wh8wSeY5AuDXvu2tv9g/PW9wIJmPuKSHMA==
},
}, flattened)
end)
it("origin error do not loss when enable flatten_errors - (#12167)", function()
local input = {
_format_version = "3.0",
consumers = {
{
id = "a73dc9a7-93df-584d-97c0-7f41a1bbce3d",
username = "test-consumer-1",
},
{
id = "a73dc9a7-93df-584d-97c0-7f41a1bbce32",
username = "test-consumer-1",
},
},
}

local flattened = post_config(input)

assert.equals(1, #flattened,
"unexpected number of flattened errors")
assert.equals("uniqueness violation: 'consumers' entity with username set to 'test-consumer-1' already declared", flattened[1].errors[1].message)
assert.equals("entity", flattened[1].errors[1].type)
oowl marked this conversation as resolved.
Show resolved Hide resolved
end)
end)


Expand Down