-
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(dao) cassandra to handle ngx.null with check_*_constraints #3355
Conversation
No regression test case? :/ |
@@ -357,7 +357,7 @@ local function check_unique_constraints(self, table_name, constraints, values, p | |||
|
|||
for col, constraint in pairs(constraints.unique) do | |||
-- Only check constraints if value is non-null | |||
if values[col] ~= nil then | |||
if values[col] ~= nil and values[col] ~= ngx.null then |
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.
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.
Well, here we need to pass something to DAO. If we nil
then that field will not be updated (or nullified
). If we set it to cassandra.null
then the generic implementations needs to know about the database. ngx.null
is common way to tell the strategies to do something. Serialize function already handles this:
kong/kong/dao/db/cassandra.lua
Line 314 in 12244ec
if value == nil or value == ngx.null then |
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.
Ah true. Alright, then I think all we need would be a regression test for this?
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.
That's right. I will be adding it.
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.
@thibaultcha the test was added.
12244ec
to
e15802c
Compare
e15802c
to
4b1d0e0
Compare
local ok, err = schema.self_check(schema, t, options.dao, options.update) | ||
if ok == false then | ||
return false, nil, err | ||
end | ||
for _, column in ipairs(nil_c) do | ||
t[column] = ngx.null | ||
end |
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 don't like this, but there is no other way around it. Only way is to update all the self_check
s to work with ngx.null
s?
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.
Agreed, this change makes sense for backwards-compatibility purposes.
local ok, err = schema.self_check(schema, t, options.dao, options.update) | ||
if ok == false then | ||
return false, nil, err | ||
end | ||
for _, column in ipairs(nil_c) do | ||
t[column] = ngx.null | ||
end |
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.
Agreed, this change makes sense for backwards-compatibility purposes.
assert.is_table(json.enabled_plugins) | ||
assert.True(#json.enabled_plugins > 0) | ||
dao:truncate_tables() | ||
db:truncate() |
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.
These operations are now handled by get_db_utils()
. Will update locally but good for the next time :)
Merged! |
Because `self_check` for plugins currently does a new DB `:select()` to check for foreign entities, if the `service_id` or `route_id` fields are `ngx.null` (from a PATCH with JSON NULL), then Cassandra produces an error: [Invalid] Invalid null value in condition for column id And PostgreSQL as well, for another reason: runtime error: ./kong/dao/schemas/plugins.lua:101: attempt to concatenate field 'service_id' (a userdata value) We should avoiding giving `ngx.null` to `self_check` since the entire old schema was never designed to play nice with it, and because external plugins might be broken if we do so. This change improves backwards-compatibility. Fix #3308 From #3355 Signed-off-by: Thibault Charbonnier <thibaultcha@me.com>
Because `self_check` for plugins currently does a new DB `:select()` to check for foreign entities, if the `service_id` or `route_id` fields are `ngx.null` (from a PATCH with JSON NULL), then Cassandra produces an error: [Invalid] Invalid null value in condition for column id And PostgreSQL as well, for another reason: runtime error: ./kong/dao/schemas/plugins.lua:101: attempt to concatenate field 'service_id' (a userdata value) We should avoiding giving `ngx.null` to `self_check` since the entire old schema was never designed to play nice with it, and because external plugins might be broken if we do so. This change improves backwards-compatibility. Fix Kong#3308 From Kong#3355 Signed-off-by: Thibault Charbonnier <thibaultcha@me.com>
Summary
Fix some issues with C* when doing verifications on constraints while the value was
ngx.null
.Full changelog
ngx.null
incheck_unique_constraints
ngx.null
incheck_foreign_constaints
How to reproduce the problem
Issues resolved
Fix #3308