From 8a978559f3dd68b36c81e3e02a757097dd11a96e Mon Sep 17 00:00:00 2001 From: Aapo Talvensaari Date: Tue, 27 Aug 2024 19:16:47 +0300 Subject: [PATCH] fix(db): targets:upsert to properly handle errors ### Summary `kong.db.targets:upsert` was not handling errors with `kong.db.targets:each_for_upstream` correctly. This fixes it. Signed-off-by: Aapo Talvensaari --- kong/db/dao/targets.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kong/db/dao/targets.lua b/kong/db/dao/targets.lua index 42efb3a3f070..8d0191236d14 100644 --- a/kong/db/dao/targets.lua +++ b/kong/db/dao/targets.lua @@ -66,7 +66,10 @@ function _TARGETS:upsert(pk, entity, options) -- backward compatibility with Kong older than 2.2.0 local workspace = workspaces.get_workspace_id() local opts = { nulls = true, workspace = workspace } - for existent in self:each_for_upstream(entity.upstream, nil, opts) do + for existent, err, err_t in self:each_for_upstream(entity.upstream, nil, opts) do + if not existent then + return nil, err, err_t + end if existent.target == entity.target then -- if the upserting entity is newer, update if entity.created_at > existent.created_at then @@ -79,7 +82,6 @@ function _TARGETS:upsert(pk, entity, options) end -- if upserting entity is older, keep the existent entity return true - end end