Skip to content
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

Merged
merged 1 commit into from
Apr 21, 2017
Merged

Conversation

Tieske
Copy link
Member

@Tieske Tieske commented Apr 19, 2017

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.

Issues resolved

Fixes #2415

@Tieske Tieske self-assigned this Apr 19, 2017
@Tieske Tieske force-pushed the fix/uuid-lookups branch from a01814e to 059e66c Compare April 20, 2017 13:06
@Tieske Tieske added this to the 0.10.2 milestone Apr 20, 2017
@@ -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
Copy link
Contributor

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"

Copy link
Member Author

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.

local rows, err = dao:find_all(filter)
if err then
return nil, err
elseif is_uuid and not next(rows) then
Copy link
Contributor

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)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same?

Copy link
Contributor

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.
@Tieske Tieske force-pushed the fix/uuid-lookups branch from 059e66c to bdd305a Compare April 21, 2017 10:27
@Tieske Tieske merged commit 254befa into master Apr 21, 2017
@thibaultcha thibaultcha deleted the fix/uuid-lookups branch April 28, 2017 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

entity lookups on xxx_or_id do not work as expected
2 participants