joerussbowman / gaeutilities

gaeutilities - A collection of utilities to help with application development on Google Appengine
http://gaeutilities.appspot.com
BSD 3-Clause "New" or "Revised" License
78 stars 4 forks source link

Using session.delete_item("key") Produces Error with Cookie Sessions #7

Closed bdoms closed 14 years ago

bdoms commented 14 years ago

I'm using a cookie session and I just tried to delete something from the session for the first time, and I got this error:

session.delete_item("key")
File "gaeutils/sessions.py", line 1055, in delete_item
self.__delitem__(keyname)
File "gaeutils/sessions.py", line 1067, in __delitem__
sessdata = self._get(keyname = keyname)
File "gaeutils/sessions.py", line 677, in _get
return self.session.get_item(keyname)
AttributeError: 'Session' object has no attribute 'session'

There does appear to be support for deleting from cookie sessions, but that line in the stack trace - 1067 - is throwing an error before the code can get to the cookie-specific section. The problem is that it's calling into a method (self._get) that is not meant to support cookie sessions.

An easy fix (though I'm not sure if this is the best way) is to check for the session attribute before calling into it:

676,678c676,680
<         if keyname != None:
<             return self.session.get_item(keyname)
<         return self.session.get_items()

---
>         if hasattr(self, "session"):
>             if keyname != None:
>                 return self.session.get_item(keyname)
>             return self.session.get_items()
>         return None

I think that patch still allows for the old behavior while now supporting deleting from cookie sessions as well.

joerussbowman commented 14 years ago

I'll take a look at this as soon as I can, hopefully sometime this weekend.

joerussbowman commented 14 years ago

I concur, your suggested patch made the most sense, and has been applied. Thanks.