fix: preserve plugins with empty config using targeted approach#3277
fix: preserve plugins with empty config using targeted approach#3277DSingh0304 wants to merge 5 commits intoapache:masterfrom
Conversation
This introduces a targeted fix to preserve empty plugin configurations (like key-auth) during the data cleaning process. - Adds producePreservePlugins to mark empty plugin configs before cleaning - Adds produceRemovePreserveMarkers to restore them after cleaning - Keeps default cleaning behavior for other fields to prevent validation errors
There was a problem hiding this comment.
Hi, pls add a test for this case.
There was a problem hiding this comment.
Yes i will add the test in some time.
There was a problem hiding this comment.
Hey I have added the test...
Baoyuantop
left a comment
There was a problem hiding this comment.
The PR description also mentions fixing #3270
We also need to write tests to verify this issue.
|
|
||
| // Create a route via API with key-auth plugin having empty configuration | ||
| const response = await postRouteReq(e2eReq, { | ||
| name: routeNameWithEmptyPlugin, | ||
| uri: routeUri, | ||
| plugins: { | ||
| 'key-auth': {}, | ||
| }, | ||
| upstream: { | ||
| nodes: [{ host: 'httpbin.org', port: 80, weight: 1 }], | ||
| type: 'roundrobin', | ||
| }, | ||
| }); | ||
|
|
There was a problem hiding this comment.
I believe this is also part of the testing path and should be created within the testing process rather than through the API.
There was a problem hiding this comment.
Oh okay I ll look into it..
I will add it soon... |
Baoyuantop
left a comment
There was a problem hiding this comment.
It is recommended to modify the calling parameters of the deepCleanEmptyKeys function, rather than adding complex marking logic to the pipeline.
export const produceDeepCleanEmptyKeys = (opts: ICleanerOptions = {}) =>
produce((draft) => {
deepCleanEmptyKeys(draft, {
emptyObjectsCleaner: false, // Key change: Do not clean up empty objects.
...opts,
});
});
Thanks for the suggestion! I've implemented the change to use |
429b370 to
0ad687a
Compare
Why submit this pull request?
What changes will this PR take into?
Fields with empty object values (
{}) were being silently dropped when saving. This affects:key-auth,prometheus,echo)discovery_argswhen using Service DiscoveryRoot Cause: The
fast-cleanlibrary used in src/utils/producer.ts hasemptyObjectsCleaner: trueby default, which removes empty objects before sending data to the server.Fix: Set
emptyObjectsCleaner: falsein the deepCleanEmptyKeys function to preserve empty objects.Related issues
fix #3269
fix #3270
Checklist: