Skip to content

Commit

Permalink
fix(db): targets:upsert to properly handle errors
Browse files Browse the repository at this point in the history
### 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 <[email protected]>
  • Loading branch information
bungle committed Aug 27, 2024
1 parent 4d7934b commit 8a97855
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kong/db/dao/targets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -79,7 +82,6 @@ function _TARGETS:upsert(pk, entity, options)
end
-- if upserting entity is older, keep the existent entity
return true

end
end

Expand Down

0 comments on commit 8a97855

Please sign in to comment.