diff --git a/kong/db/schema/others/declarative_config.lua b/kong/db/schema/others/declarative_config.lua index 42b165f7e7ff..7cae8ffe3c64 100644 --- a/kong/db/schema/others/declarative_config.lua +++ b/kong/db/schema/others/declarative_config.lua @@ -41,9 +41,7 @@ local foreign_children = {} do local tb_nkeys = require("table.nkeys") - local request_aware_table = require("kong.tools.request_aware_table") - - local CACHED_OUT + local buffer = require("string.buffer") -- Generate a stable and unique string key from primary key defined inside -- schema, supports both non-composite and composite primary keys @@ -55,17 +53,27 @@ do return tostring(object[primary_key[1]]) end - if not CACHED_OUT then - CACHED_OUT = request_aware_table.new() - end + local buf = buffer.new() - CACHED_OUT:clear() + -- The logic comes from get_cache_key_value(), which uses `id` directly to + -- extract foreign key. + -- TODO: extract primary key recursively using pk_string(), KAG-5750 for i = 1, count do local k = primary_key[i] - insert(CACHED_OUT, tostring(object[k])) + local v = object[k] + + if type(v) == "table" and schema.fields[k].type == "foreign" then + v = v.id + end + + buf:put(tostring(v or "")) + + if i < count then + buf:put(":") + end end - return concat(CACHED_OUT, ":") + return buf:get() end end diff --git a/kong/tools/request_aware_table.lua b/kong/tools/request_aware_table.lua index beaa08f4b6e9..3a1cc8894373 100644 --- a/kong/tools/request_aware_table.lua +++ b/kong/tools/request_aware_table.lua @@ -1,5 +1,9 @@ --- NOTE: tool is designed to assist with **detecting** request contamination -- issues on CI, during test runs. It does not offer security safeguards. +-- +-- TODO: need to resolve the following issues in debug mode, +-- 1. `:clear` could not clear elements inserted by `table.insert()` +-- 2. `table.concat()` couldn't work for elements assigned using `indexing` local table_new = require("table.new") local table_clear = require("table.clear")