My GAE Python app has a kind called “User”, with various custom fields. Recently, when my app has no activity overnight, I will get an error when I try to log in the next morning.
During login, I get an id (from Facebook) which is the key_name for the entity in the Datastore:
user = User.get_by_key_name(id_from_facebook)
logging.debug(user.favorite_color)
This causes an error because the entity returned is actually some class from the google library, and therefore doesn’t have the field “favorite_color”. However, it is getting “something” from the datastore, so I checked the object’s contents:
for key in user.__dict__.keys():
log.debug("%s: %s" % (key, user.__dict__[key]))
This shows keys that aren’t in my “User” kind, like “_first_name”, “_last_name”, and “_email”.
I also tried importing my class from “myapp.models” inside the method instead of at the top of the file, but nothing changed. Once I shutdown the instance running on GAE and access my app again to start an new instance, however, it works fine.
My only clue was that I have heard about there being a discrepancy between what my app imports and what GAE imports, but nothing else. Is there anything I can do besides copying all of my users into a new, unique type (like “MyUser”)?
EDIT:
I found that the undesired class was actually “User” from Kay Framework, which is also in my project. However, I don’t import that class anywhere in my code, especially not in the module where the error is occurring.
You’re probably importing the
Userclass fromgoogle.appengine.api.users.Fortunately, Python makes this sort of thing easy to track down, because imports are explicit. Just check your import lines at the top of your module, and determine where that object is coming from.