-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): remove and restore nulls before and after transformations #12284
Conversation
kong/db/schema/init.lua
Outdated
@@ -930,6 +930,7 @@ function Schema:validate_field(field, value) | |||
local field_schema = get_field_schema(field) | |||
-- TODO return nested table or string? | |||
local copy = field_schema:process_auto_fields(value, "insert") | |||
-- Changes in custom entity check only applies to copy, not to value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is intended or bug. Leave a comment for reminder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as this is validate_field
function. The process auto fields is just executed so that the validation can pass or something. Thus I don't think we need to add this comment. Or if we add the comment, the comment should explain why copy, and not to point something that might be totally false. Thus I lean removing this comment as bad comment is worse than no comment at all. Perhaps a more generic "-- TODO: explain why we need to make a copy?"
-- Changes in custom entity check only applies to copy, not to value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
I replaced the comment with:
TODO: explain why we need to make a copy?"
The issue is, field_schema:validate(copy)
may have config customizations. If so, the customizations only go to the copy
, not the original value
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@outsinre, yes, the customizations I think are fine. This is validation time, the validation should not change the entitity I think. So that's why it is probably copied so that it does not change the original entity on validation. Perhaps it does the change on some other time.
99b2929
to
7484fde
Compare
d773d55
to
84ae9ee
Compare
4bd0659
to
c8c93b7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some change requests.
kong/db/schema/init.lua
Outdated
@@ -930,6 +930,7 @@ function Schema:validate_field(field, value) | |||
local field_schema = get_field_schema(field) | |||
-- TODO return nested table or string? | |||
local copy = field_schema:process_auto_fields(value, "insert") | |||
-- Changes in custom entity check only applies to copy, not to value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as this is validate_field
function. The process auto fields is just executed so that the validation can pass or something. Thus I don't think we need to add this comment. Or if we add the comment, the comment should explain why copy, and not to point something that might be totally false. Thus I lean removing this comment as bad comment is worse than no comment at all. Perhaps a more generic "-- TODO: explain why we need to make a copy?"
-- Changes in custom entity check only applies to copy, not to value |
Current declarative config uncondtionally removes nulls before loading into LMDB, which would reset relavant config fields to their default values. If their default values are `nil` and the code fails to dectect it, Kong will error! For example, config update may not be applied to core entities or plugins. This PR removes nulls only if relevant schemas have transformations defined, and restore those nulls after transformation. Therefore, when loaded, entities preserve their nulls. This fix does not prevent other components removing nulls accidentally. So please always check both `nil` and `null` for code robustness. This PR will skip transformations if there is not transformation defitions. As most schemas do not have transformations, this would greatly improve performance. Addtionally, this PR change recursive function to be iterative to boost performance. Signed-off-by: Zachary Hu <zachary.hu@konghq.com>
Co-authored-by: Aapo Talvensaari <aapo.talvensaari@gmail.com>
5ed05f8
to
cfbfb5c
Compare
Current declarative config uncondtionally removes nulls before loading into LMDB, which would reset relavant config fields to their default values.
If their default values are
nil
and the code fails to dectect it, Kong will error! For example, config update may not be applied to core entities or plugins.This PR removes nulls only if relevant schemas have transformations defined, and restore those nulls after transformation. Therefore, when loaded, entities preserve their nulls.
This fix does not prevent other components removing nulls accidentally. So please always check both
nil
andnull
for code robustness.This PR will skip transformations if there is not transformation defitions. As most schemas do not have transformations, this would greatly improve performance.
Addtionally, this PR change recursive function to be iterative to boost performance.
Local debug info.
Summary
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
Fix #FTI-5260