From c3894f9e495f22c9bfc1ba7989d65f9ffeb19143 Mon Sep 17 00:00:00 2001 From: Xiaochen Wang Date: Mon, 4 Nov 2024 15:52:07 +0800 Subject: [PATCH] fix(sync/lmdb): construct right pk string for entity with multiple primary keys For the entity with multiple primary keys, like consumer_group_consumers, the pk_string() function construct incorrect pk string like `table: 0x028a49eda0:table: 0x0289c257b8`. Because it does not extract the internal id value. Here, we fix it with original lmdb logic get_cache_key_value(). Note this method directly gets id field name. --- kong/db/schema/others/declarative_config.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kong/db/schema/others/declarative_config.lua b/kong/db/schema/others/declarative_config.lua index 42b165f7e7ff..666b340bb898 100644 --- a/kong/db/schema/others/declarative_config.lua +++ b/kong/db/schema/others/declarative_config.lua @@ -60,9 +60,18 @@ do end CACHED_OUT:clear() + + -- The logic comes from get_cache_key_value(), which uses `id` directly to + -- extract foreign key. 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 + + insert(CACHED_OUT, tostring(v or "")) end return concat(CACHED_OUT, ":")