Fair question. Dunno the answer. It was just an example. The real 
application is that I'm filling the dict with other stuff. It's keeping 
track of the state of my GUI -- active tabs and stuff. So in that case, the 
empty session.myvar condition would not be triggered. In any event, I have 
a breakpoint set on session.myvar getting reset and it is never reached, so 
the empty dict condition isn't getting triggered.


On Friday, June 6, 2014 8:28:29 PM UTC+8, Anthony wrote:
>
> Just to be clear, when you delete session.myvars[somevar], you are sure 
> session.myvars still contains other dictionaries and is not at this point 
> an empty dictionary (which would trigger the model code to refill it)?
>
> On Friday, June 6, 2014 3:46:11 AM UTC-4, weheh wrote:
>>
>> I'm using an ajax call to default.py controller. The default.py sets a 
>> session variable. Paraphrased, it looks like this:
>>
>> # model
>> if not session.myvars:
>>     session.myvars = dict(
>>         somevar=dict(),
>>         othervar=dict(),
>>         ...
>>         )
>>
>>
>> # view
>> <script> 
>> ...
>>         ajax("{{= URL('default', 'setvar', args=[...])}}",[],":eval");
>> ...
>> </script>
>>
>>
>>
>> # default.py
>> if False:
>>     session = current.session  # to make Eclipse happy
>>
>> def setvar():
>>     ...
>>     del session.myvars['somevar']
>>     ...
>>     return ''
>>
>>
>>
>>
>>
>> In other controllers, the session.myvars['somevar'] is given a useful 
>> value.
>>
>> Here's the really strange thing. If the ajax script is triggered, the 
>> session.myvars['someval'] dict gets deleted as desired. However, only 
>> temporarily! When another controller later on uses session.myvars, the old 
>> session.myvars['somevar'] is still in existence.
>>
>> If I reproduce this by putting the del session.myvars['somevar'] in one 
>> of my other controllers, the session.myvars['somevar'] gets deleted 
>> permanently, as desired.
>>
>> This doesn't just happen for deleting session variables. It also happens 
>> for setting session variables inside the default.py controller.
>>
>> OK, here's another clue. Ready? When I put a breakpoint in eclipse and 
>> stop the default controller from executing straight through, then the 
>> session variable gets deleted for sure.
>>
>> Why is this happening? This has got my head spinning! Is there something 
>> special about default.py that I don't know about? Are you not supposed to 
>> manipulate session variables in there? Is there a cache issue going on here?
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to