[albatross-users] User input sought

Andrew McNamara andrewm at object-craft.com.au
Fri Dec 6 12:34:16 EST 2002


>>> Hmm...  Does this mean that you are doing something like this:
>>>     ctx.add_session_vars('blah')
>>>
>>> Without doing this:
>>>     ctx.locals.blah = 42
>>>
>>> If that is the case, Andrew and I have decided that it might make
>>> sense to make the add_session_vars() method create a ctx.locals value
>>> and set it to None if it does not currently exist in ctx.locals
[...]
>Okay, I see what you meant.  No, in the page_enter I did not initialize
>"blah", I only called ctx.add_session_vars("blah"), it was set though a
>form field and this doesn't appear to get the variable added to the
>session.
>
>It would be nice if this worked, but I can see the issue if blah was
>expected to be a dict or a list and was set to None instead of [] or {}.
>Still, I have a very large for with several fields that need to be in
>the session, and there is a lot of blah = blah1 = blah2 = None
>code in my page_enter, so I guess the lessor evil would be defaulting to
>none as you suggest, and I'll handle lists/dicts/objects myself.

As you say, this approach (add_session_vars setting undefined vars to None)
fails where the application is expecting some other data type. While the
application would have failed anyway, the proposed change may obscure the
real cause of the problem.

Another possible option is to have add_session_vars raise an exception if
the variable doesn't already exist - the attraction of this approach is
that you can raise the error right at the point where the bug exists. The
downside is that it will break existing working code of the following form
(although the fix is easy):

    ctx.add_session_vars('blah')
    ctx.locals.blah = 1

So - would the community prefer explicit over implicit (the Python
philosophy) at the cost of a small amount of easily fixed breakage?

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/



More information about the Albatross-users mailing list