While I was developing Last Tweets, I encountered a problem on production server, which is never happened on development server. The traceback looks like:
Traceback (most recent call last): File "/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 499, in __call__ handler.get(*groups) File "/base/data/home/apps/lastweet/1.12/index.py", line 77, in get 'tweets': u._tweets_, File "/base/data/home/apps/lastweet/1.12/lastweet/user.py", line 47, in _get_tweets return pickle.loads(self.tweets) File "/base/python_dist/lib/python2.5/pickle.py", line 1367, in loads return Unpickler(file).load() File "/base/python_dist/lib/python2.5/pickle.py", line 852, in load dispatch[key](self) KeyError: '\x00' Traceback (most recent call last): File "/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 499, in __call__ handler.get(*groups) File "/base/data/home/apps/lastweet/1.12/index.py", line 77, in get 'tweets': u._tweets_, File "/base/data/home/apps/lastweet/1.12/lastweet/user.py", line 47, in _get_tweets return pickle.loads(self.tweets) File "/base/python_dist/lib/python2.5/pickle.py", line 1367, in loads return Unpickler(file).load() File "/base/python_dist/lib/python2.5/pickle.py", line 852, in load dispatch[key](self) KeyError: '\x00'
Where u._tweets_ is a property of data model class, defined as
_tweets_ = property(_get_tweets, _set_tweets)
A side note: when you need your own property (method or attribute), you need to prefix with an underscore _. Or GAE treats it as part of data. Even you have prefixed an underscore, if the name (_tweets) is same as a data field (tweets) and with property functions (_get_tweets), that may cause endless calls.
This error happens on when I use _get_tweets on production server, it does things like:
import pickle ... return pickle.loads(self.tweets)
Then I got a KeyError. I resolved this with:
return pickle.loads(str(self.tweets))
Its dirty. I still dont know what Google did to pickle module. I got the pickled data and tried to unpickle on my computer, the result is correct. So that may only be something in unpickling. By the way, the tweets is a TextProperty.
Thanks for this -- ran in to the same problem. Yup -- worked great on development, killed my live site...
ReplyDeleteThanks for this, I also ran into the same problem, though it showed up on my dev server. Once I saw you used str() it was obvious what happened. Datastore isnt returning a string, it is returning an instance of google.appengine.api.datastore_types.Text. Pickle spots the different and barfs.
ReplyDeleteThanks again!
[Ironically I work at Google.]