On Tue, 2009-02-03 at 13:52 -0800, Vladimir Shulyak wrote:
> Any progress on this problem?
> I've got exactly the same problem with sessions on ubuntu/database-
> backend sessions. But the most interesting thing that variables like
> instances of large classes are deleted while simple instances like
> integers are fine.
> 
> class Cart():
> 
>       items = {}
>       totalPrice = 0
>       count = 0
>       company = 0
> 
> items variable holds a dictionary of objects (instances of
> models.Model), other variables are just integer objects. items var
> becomes empty after some time, other variables are ok. Seems like I am
> not allowed to hold model instances in session... But why?

Is it something special about model instances, or just anything that you
are setting in the dictionary? This sounds like it might just be a "deep
change" case, requiring you to manually mark the session as dirty (see
[1]).

Note that the following code will not save the data to the session
automatically:

        def some_view(request, ...):
             request.session['cart'].items['foo'] = bar
             ....
             return ...

You haven't assigned anything to the session, so it doesn't get
automatically marked as dirty (you have updated something in place and
request.session has absolutely no way to know that). This is the same
situation as if you have ever used Python's various shelving modules.

Direct assignments to request.session result in automatic saving.
Updates in place to objects inside request.session require setting the
modified flag. It sounds like the situation you are describing might be
that case.

If not, again, the same request applies to you as to the original
poster: come up with a very small, self-contained example that
demonstrates the problem. We can't debug what we can't reproduce.


[1]
http://docs.djangoproject.com/en/dev/topics/http/sessions/#when-sessions-are-saved

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to