Skip to content

Commit

Permalink
fix(dbless): fix error data loss caused by weakly typed of function i…
Browse files Browse the repository at this point in the history
…n declarative_config_flattened function (#12167)

FTI-5584

(cherry picked from commit 410d9bd)
  • Loading branch information
oowl authored and bungle committed Jan 18, 2024
1 parent 5974bb0 commit 35c79dd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,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
add_entity_errors(entity_type, entity, err_t_i, flattened)

else
Expand Down
37 changes: 37 additions & 0 deletions spec/02-integration/04-admin_api/15-off_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2697,6 +2697,43 @@ 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",
tags = { "consumer-1" },
},
{
id = "a73dc9a7-93df-584d-97c0-7f41a1bbce32",
username = "test-consumer-1",
tags = { "consumer-2" },
},
},
}
local flattened = post_config(input)
validate({
{
entity_type = "consumer",
entity_id = "a73dc9a7-93df-584d-97c0-7f41a1bbce32",
entity_name = nil,
entity_tags = { "consumer-2" },
entity = {
id = "a73dc9a7-93df-584d-97c0-7f41a1bbce32",
username = "test-consumer-1",
tags = { "consumer-2" },
},
errors = {
{
type = "entity",
message = "uniqueness violation: 'consumers' entity with username set to 'test-consumer-1' already declared",
}
},
},
}, flattened)
end)
end)


Expand Down

0 comments on commit 35c79dd

Please sign in to comment.