Well, you're making two Ajax calls simultaneously, so I would think there
could be a race condition with the sessions, but with file based sessions,
access to the session should be serialized.
Anthony
On Tuesday, June 10, 2014 9:15:37 PM UTC-4, weheh wrote:
>
> Very temporarily :-) I check it out by inspecting session every step of
> the way before, during and after the ajax call.
>
> Now, one new thing I noticed is that my number of sessions has exploded,
> which makes no sense at all. The ajax call to the default controller is
> happening from within an anonymous function triggered by a bootstrap nav
> click. Looks something like this:
>
> mytabs.on("show.bs.tab", function(e) {
> ajax("{{= URL('default', 'settab', args=[...])",[],":eval");
> web2py_component(...); // used to populate contents of tab
> });
>
> I'm not sure whether this would account for why I have so many sessions
> sprouting up. But I do know that when I took out this code and found a
> different implementation that sets the session from within the controller
> that does the populating of the tab's div on click, then all of a sudden my
> problems go away.
>
> So bottom line, I go this solved. But the reasons are mysterious to me. I
> don't see why I should be getting so many sessions from the ajax call, or
> even whether that was my culprit. Unfortunately, I lost so much time
> chasing this issue I have to move on. But I'd like to figure out what
> actually was going on under the hood.
>
>
> On Friday, June 6, 2014 9:33:02 PM UTC+8, Anthony wrote:
>>
>> You said the dict gets deleted temporarily? How temporarily? How are you
>> checking that? Is it only deleted during the current request? If so, sounds
>> like for some reason the session isn't getting saved. Are you using the
>> default file based sessions?
>>
>> On Friday, June 6, 2014 9:08:38 AM UTC-4, weheh wrote:
>>>
>>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.