Closed e2jk closed 14 years ago
Apparently this happened because I still had the cookie in my browser while the datastore had no such entity. Deleting the cookie in the browser enabled me to continue, but this still doesn't fix the issue that the session should not error out like this. I will investigate putting this db.get call in an except block.
Also, in order to see this bug the session must not be in memcached. So the conditions are:
they are inducing my wife on tuesday, not sure when i will have time to look at this.
I actually just encountered this today on a live app. Good to know that there's a workaround (telling the user seeing the problem to delete their cookies).
I think the fastest solution would be to just put a try/except around the offending part:
--- a/sessions.py
+++ b/sessions.py
@@ -138,8 +138,10 @@ class _AppEngineUtilities_Session(db.Model):
return None
# Not in memcache, check datastore
-
- ds_session = db.get(str(session_key))
+ try:
+ ds_session = db.get(str(session_key))
+ except:
+ ds_session = None
if ds_session:
sessionAge = datetime.datetime.now() - ds_session.last_activity
if sessionAge.seconds > session_obj.session_expire_time:
But there's probably a more elegant solution.
I used the patch above, put it in via the web interface. Grab the master branch and you should be good. I'll see about getting a release rolled up, but as my daughter was born last night I have other priorities at the moment.
I'am affected by this bug :(
: session = gaeutilities.sessions.Session()
: File "/base/data/home/apps/odelis-net/1.350624512923347810/odelis/gaeutilities/sessions.py", line 562, in __init__
: self.session = _AppEngineUtilities_Session.get_session(self)
: File "/base/data/home/apps/odelis-net/1.350624512923347810/odelis/gaeutilities/sessions.py", line 142, in get_session
: ds_session = db.get(str(session_key))
: File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 1471, in get
: return get_async(keys, **kwargs).get_result()
: File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 1430, in get_async
: keys, multiple = datastore.NormalizeAndTypeCheckKeys(keys)
: File "/base/python_runtime/python_lib/versions/1/google/appengine/api/datastore.py", line 180, in NormalizeAndTypeCheckKeys
: keys = [_GetCompleteKeyOrError(key) for key in keys]
: File "/base/python_runtime/python_lib/versions/1/google/appengine/api/datastore.py", line 2409, in _GetCompleteKeyOrError
: key = Key(arg)
: File "/base/python_runtime/python_lib/versions/1/google/appengine/api/datastore_types.py", line 364, in __init__
: raise datastore_errors.BadKeyError('Invalid string key %s.' % encoded)
: BadKeyError: Invalid string key agpvZGVsaXMtbmV0ciMLEhtfQXBwRW5naW5lVXRpbGl0aWVzX1Nlc3Npb24Y.
I am using gaeutilities for some months now, and have never seen this error yet. I haven't changed anything in the last week, and 2 days ago (lat time I logged in) everything was working fine. But now I try to log in and I directly get this exception:
Could this be due to the fact that you are passing a string to db.get, when the docs say that it shoudl be a Key object?
Or could this be due to an old Session being stored in the datastore?
Anyways, this should not generate this unhandled exception visible to the end user. I guess that if the db.get fails, the user should just not be logged in and don't see the exception... Any thoughts?