From 662da5d96261cb17c9e1e782d656ab7ff9ba6f9f Mon Sep 17 00:00:00 2001 From: Xiaochen Wang Date: Thu, 31 Oct 2024 15:35:21 +0800 Subject: [PATCH] fix(incremental sync): fixed ws_id processing in _set_entity_for_txn --- kong/db/declarative/import.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/kong/db/declarative/import.lua b/kong/db/declarative/import.lua index 43fa58a4e764..f7536389cdbf 100644 --- a/kong/db/declarative/import.lua +++ b/kong/db/declarative/import.lua @@ -326,6 +326,7 @@ local function _set_entity_for_txn(t, entity_name, item, options, is_delete) local is_foreign = fdata.type == "foreign" local fdata_reference = fdata.reference local value = item[fname] + local fws_id = fdata.unique_across_ws and kong.default_workspace or ws_id -- value may be null, we should skip it if not value or value == null then @@ -345,11 +346,7 @@ local function _set_entity_for_txn(t, entity_name, item, options, is_delete) value_str = pk_string(kong.db[fdata_reference].schema, value) end - if fdata.unique_across_ws then - ws_id = kong.default_workspace - end - - for _, wid in ipairs {ws_id, GLOBAL_WORKSPACE_TAG} do + for _, wid in ipairs {fws_id, GLOBAL_WORKSPACE_TAG} do local key = unique_field_key(entity_name, wid, fname, value_str or value) -- store item_key or nil into lmdb @@ -363,7 +360,7 @@ local function _set_entity_for_txn(t, entity_name, item, options, is_delete) value_str = pk_string(kong.db[fdata_reference].schema, value) - for _, wid in ipairs {ws_id, GLOBAL_WORKSPACE_TAG} do + for _, wid in ipairs {fws_id, GLOBAL_WORKSPACE_TAG} do local key = foreign_field_key(entity_name, wid, fname, value_str, pk) -- store item_key or nil into lmdb