0
votes

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

SELECT * FROM UserEntry where email = '[email protected]'

and also query it by encoded key string, e.g.:

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','[email protected]')

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, "[email protected]");

This code results in following exception:

javax.jdo.JDOObjectNotFoundException: Could not retrieve entity of kind UserEntry with key UserEntry("[email protected]")

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

2
It would help if you posted the actual values used instead of 'cy1hcHByIAsSCVVzZXJFbnRyeM' and "[email protected]". Then I can check easily whether these are equivalent. The ones you gave are not; 'cy...eM' is not even a valid key. - Guido van Rossum
The actual value is email address of our user, which is kind of private information.. But I can assure you that the name of the encoded key decodes correctly to the given email. - Jakub Stejskal
So you are saying there is one key, and one key only, for which quering using KEY('sdfasdfasdfasfsdfasdfsd') works but the same query using KEY('classname', 'keyname') fails? Consistently? And you cannot reproduce that with other keys? Then please email me the details privately. - Guido van Rossum
I cannot confirm that it's the only one, as I didn't test all of them, but it's the only one I've found. The behaviour is consistent for this entity. I've sent you the actual values by email. - Jakub Stejskal

2 Answers

2
votes

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

0
votes

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.