views:

26

answers:

1

UPDATE: After further testing, it seems this issue affects all child entities in my entity group. My root parent for all these different instances is User kind, which is my own creation, not the built in User kind. After removing the parent=user from the constructor of the child Kind, the get_by_key_name works as expected. However, I would like to be able to use the Entity Group functionality along with the defined keys, if that is possible.

-- Hi, I am attempting to use defined key names for speedier querying in my GAE project.

However, I have run into an odd issue where I cannot fetch they key. This code does not seem to work:

for l in Logins.all().fetch():
    print Login.get_by_key_name(l.key().name())

Some notes:

  • I have only tested in the SDK
  • l.key().name() Returns the key name string listed with the entity when I look in the data store. I can copy and paste the string out of the data story and use that as the arg to get_by_key_name() and that does not work either.

  • keynames for the Login kind are all prefixed with an "l" (i.e. lowercase "L") and are other wise all lowercase and may contain underscores or dashes but are under 500 bytes.

  • Other kind serches like this work.

  • The key is a interpolation of 2 properties of the Login kind, and I can fetch the objects just fine using regular .filter() methods
  • The "parent" for the instances is a User class. (mentioning in case this has some bearing on the way I have to fetch)

So I have to ask, is there any obvious reasons why this would not work? Any known issues with key name searches using the SDK?

+2  A: 

Your second comment is correct, AFAIK. The parent/child relationship is similar to a directory or folder structure in your filesystem. Your key is (conceptually) /parents/[parent_keyname]/logins/[login_keyname]. So if you try to fetch /logins/[login_keyname] you will not get your entity. (There is no rule that all Logins must be children of Parents; `get_by_key_name() must be told of the parent relationship every time.)

In my own code, I have ended up building my keys myself with Key.from_path(). I use class methods, e.g. Login.key_for_name(some_parent, some_name) and also Login.get_by_key_name_for_parent(some_parent, some_name) (well, my method name is shorter but just making it clear. Then at least it is not possible for me to generate a key with the wrong parent/child relationship.

jhs
Thank for the reply. I discovered this yesterday finally. I was puzzled by the logic why you would need the parent in `Child.get_by_key_name()`. However, like you say, the parent's key is part of the child's key in some manner and thus you need to know the parent to build the child key. So far this is working great, except for permalinks to child entity content. I might have to take a performance hit there.