简体   繁体   中英

Appengine Datastore cannot find existing entity by unencoded key

I have existing entity in datastore. I can find it Admin Console by attribute query eg:

SELECT * FROM UserEntry where email = 'user@mail.com'

and also query it by encoded key string, eg:

SELECT * FROM UserEntry where __key__ = KEY('cy1hcHByIAsSCVVzZXJFbnRyeM')

However, when I query the entity by unencoded key, it is not found:

SELECT * where __key__ = KEY('UserEntry','user@mail.com')

From former queries I can verify that the key is correct and the same query works for other entities of the same type.

I experience the same behavior when I try to access the entity via JDO API:

pm.getObjectById(UserEntry.class, "user@mail.com");

This code results in following exception:

javax.jdo.JDOObjectNotFoundException: Could not retrieve entity of kind UserEntry with key UserEntry("user@mail.com")

How did this happen? How can I resolve this issue and avoid it in the future?

Off-line we discovered that the urlsafe key string encodes for a username with a space added, as if it encoded KEY('UserEntry','user@mail.com ') . That seems an input validation bug in the program.

Is the email property your PK on the Entity? Because if it is not, querying for it doen not make sense. Once you post your first query with the email as a ordinary property, I assume that it's not repeated on your PK, so you can not query using it on Key(type,email).

After getting the entity on admin console, click on key property to be certain that the email is part of the key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM