> > if form.accepts(request,session): > session.no_filters = session.no_filters+1 > try: > session.filter_list.update(request.vars) > except NameError: > session.filter_list = request.vars > except AttributeError: > session.filter_list = 'This is an attribute error'
The session object is a gluon.storage.Storage object, as discussed here: http://web2py.com/books/default/chapter/29/4#session. In that section, it mentions: Because session is a Storage object, trying to access an attribute/key that has not been set does not raise an exception; it returns None instead. In your code, you are expecting session.filter_list.update(request.vars) to raise a NameError before you have assigned any value to filter_list. Instead, session.filter_list simply returns None, and then you are attempting to call the .update() method on None, which is what is raising the AttributeError. If you don't catch the AttributeError, you should see that it says 'NoneType' object has no attribute 'update'. Instead, you can do: if session.filter_list: session.filter_list.update(request.vars) else: session.filter_list = request.vars Anthony