-
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(api) lookup entities by secondary field as uuid #2420
Conversation
a01814e
to
059e66c
Compare
kong/api/crud_helpers.lua
Outdated
@@ -5,16 +5,43 @@ local app_helpers = require "lapis.application" | |||
|
|||
local _M = {} | |||
|
|||
--- Will look up a value in the dao. | |||
-- Either by `id` field or by the field named by 'alternate_field'. If the value is NOT | |||
-- a uuid, then by the 'alternate_field'. If it is a uuid then it will first try |
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.
pedantic note: "a uuid" to me implies that the string we found is a UUID we generated. this could be clarified by noting the string "looks like a uuid" as opposed to is "a uuid"
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.
uuid's have a specific format and can be validated to conform to that format. Though our check is not doing that because in the past we created bad uuids.
kong/api/crud_helpers.lua
Outdated
local rows, err = dao:find_all(filter) | ||
if err then | ||
return nil, err | ||
elseif is_uuid and not next(rows) 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.
should be #rows == 0
instead of next(rows)
?
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.
same?
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.
yep, same. style + good practice + consistency with other uses (probably worth a cleanup PR to remove that anti-pattern throughout the codebase).
when the name/key/whatever field is formatted as a uuid Kong would assume that field to be the `id` field. This change will make it first try the `id` field in that case, and then the alternative field.
059e66c
to
bdd305a
Compare
when the name/key/whatever field is formatted as a uuid Kong
would assume that field to be the
id
field. This change willmake it first try the
id
field in that case, and then thealternative field.
Issues resolved
Fixes #2415