In an index function I do something like
session[request.controller].something = 'foo'

This raises a key error exception on the first visit to the controller
after restarting the browser.  Session can't find the controller name,
so I can't add an attribute to it.  So I need to initialize the
session, but not clobber it if already set.

After several hours this puzzling behavior emerged:

print session # request.controller not there, as expected.
# nothing but auth
print hasattr(session, str(request.controller)) # Prints True.
## Previous result not expected!! Why??
print request.controller in session # Prints False, as expected
session[request.controller] = {}
print hasattr(session, str(request.controller)) # Prints True
## As expected this time.
print request.controller in session # Prints True, as expected
print session[request.controller] # Prints {}, as expected

Can someone tell me why hasattr(session, str(request.controller))
returned true when request.controller was not an attribute of session?

Thanks,
Cliff Kachinske

Reply via email to