Skip to content

Commit

Permalink
check null when inserting txn
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Sep 30, 2024
1 parent 63f449b commit 478ad5d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions kong/db/declarative/import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -267,25 +267,19 @@ end
-- * <entity_name>|<ws_id>|<unique_field_name>|sha256(field_value) => <entity_name>|<ws_id>|*|<pk_string>
-- * <entity_name>|<ws_id>|<foreign_field_name>|<foreign_key>|<pk_string> -> <entity_name>|<ws_id>|*|<pk_string>
local function insert_entity_for_txn(t, entity_name, item, options)
-- copy item for remove_nulls, don't touch original item
local item = cycle_aware_deep_copy(item)

local dao = kong.db[entity_name]
local schema = dao.schema
local pk = pk_string(schema, item)
local ws_id = workspace_id(schema, options)

local item_key = item_key(entity_name, ws_id, pk)

-- serialize itme with nulls
-- serialize item with possible nulls
local item_marshalled, err = marshall(item)
if not item_marshalled then
return nil, err
end

-- after serializing we must remove nulls
item = remove_nulls(item)

t:set(item_key, item_marshalled)

-- select_by_cache_key
Expand All @@ -300,7 +294,8 @@ local function insert_entity_for_txn(t, entity_name, item, options)
local fdata_reference = fdata.reference
local value = item[fname]

if value then
-- value may be null, we should skip it
if value and value ~= null then
local value_str

if fdata.unique then
Expand Down

0 comments on commit 478ad5d

Please sign in to comment.