fix(admin): allow bidirectional format conversion for upstream.nodes in PATCH requests#13065
Open
janiussyafiq wants to merge 3 commits intoapache:masterfrom
Open
fix(admin): allow bidirectional format conversion for upstream.nodes in PATCH requests#13065janiussyafiq wants to merge 3 commits intoapache:masterfrom
janiussyafiq wants to merge 3 commits intoapache:masterfrom
Conversation
…in PATCH requests
shreemaan-abhishek
previously approved these changes
Mar 4, 2026
There was a problem hiding this comment.
Pull request overview
This PR fixes asymmetric Admin API PATCH behavior when upstream.nodes changes between array and hash-table formats by adjusting the deep-merge logic to avoid creating mixed array/hash tables during patch merges.
Changes:
- Update
core.table.merge()to replace (not recursively merge) when either the existing value or incoming value is an array. - Add an Admin API test that exercises
PATCHconversions between array and hash-tableupstream.nodesformats.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
apisix/core/table.lua |
Adjusts merge behavior to prevent invalid mixed table structures when patching between array/hash formats. |
t/admin/routes-array-nodes.t |
Adds a regression test for PATCHing upstream.nodes across both supported representations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Baoyuantop
reviewed
Mar 5, 2026
apisix/core/table.lua
Outdated
| merge(origin[k] or {}, extend[k] or {}) | ||
| else | ||
| local origin_is_array = _M.nkeys(origin[k]) == #origin[k] | ||
| local extend_is_array = _M.nkeys(v) == #v |
Contributor
There was a problem hiding this comment.
It is recommended to use table.isarray
shreemaan-abhishek
approved these changes
Mar 9, 2026
shreemaan-abhishek
approved these changes
Mar 10, 2026
Baoyuantop
approved these changes
Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes asymmetric PATCH behavior when converting
upstream.nodesbetween array and hash table formats.Problem Statement
The Admin API exhibits inconsistent behavior when patching a route's
upstream.nodesfield:{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"nodes\" validation failed: object matches none of the required"}This happens despite both formats being officially supported by the schema.
Root Cause
The
merge()function inapisix/core/table.luaonly checks if the origin value is an array before deciding whether to replace or recursively merge:When patching from hash table → array:
Solution
Modified the merge logic to check both the origin and incoming values:
Which issue(s) this PR fixes:
Fixes #13045
Checklist