Re: session modification question

2014-01-20 Thread ernando
Hi,

I agree with Daniel that your case of using session is incorrect. You have 
to think about session as a simple dictionary that stores data through 
requests. And it doesn't keep track about protecting data from changing - 
you should think about it yourself. Believe, you have to think about some 
kind of flag, that should be checked while running time-consuming operation 
and handle cases of changed data.

Thanks,
Dmitry

On Saturday, January 18, 2014 8:11:56 PM UTC+3, Spork Spork wrote:
>
> Hi,
>
> I have a question about what gets persisted when session data gets 
> updated. I've read the sessions chapter of the book, and it's not entirely 
> clear to me.
>
> Say I have two keys in the session object that I'm manipulating in a view:
>
> view1: request.session['foo'] = 'foocontent'
> view1: request.session['bar'] = 'barcontent'
> view1: goes off and does something that takes a long, long timer
>
> Meanwhile some other view fires off and changes foo:
>
> view2: request.session['foo'] = 'updateddfoocontent'
>
> Then view2 exits, and the most recent session data gets persisted.
>
> But meanwhile view1 still has the old copy of the session data. Eventually 
> it completes whatever it was doing, and updates bar:
>
> view1: request.session['bar'] = 'updatedbarcontent'
>
> Question: when view1 exits and its data gets persisted, does it overwrite 
> all of the session data, including stomping on view2's modification of foo? 
> If so, how can I ensure that at the end of view1, what gets persisted is:
>
> session['foo'] = 'updatedfoocontent'
> session['bar'] = 'updatedbarcontent'
>
> I'm using django 1.4 and db-based sessions.
>
> Thanks in advance,
>
> Spork
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6faef176-e880-4ada-a8e1-f3f01da310cf%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: session modification question

2014-01-18 Thread Daniel Roseman
On Saturday, 18 January 2014 17:11:56 UTC, Spork Spork wrote:
>
> Hi,
>
> I have a question about what gets persisted when session data gets 
> updated. I've read the sessions chapter of the book, and it's not entirely 
> clear to me.
>
> Say I have two keys in the session object that I'm manipulating in a view:
>
> view1: request.session['foo'] = 'foocontent'
> view1: request.session['bar'] = 'barcontent'
> view1: goes off and does something that takes a long, long timer
>
> Meanwhile some other view fires off and changes foo:
>
> view2: request.session['foo'] = 'updateddfoocontent'
>
> Then view2 exits, and the most recent session data gets persisted.
>
> But meanwhile view1 still has the old copy of the session data. Eventually 
> it completes whatever it was doing, and updates bar:
>
> view1: request.session['bar'] = 'updatedbarcontent'
>
> Question: when view1 exits and its data gets persisted, does it overwrite 
> all of the session data, including stomping on view2's modification of foo? 
> If so, how can I ensure that at the end of view1, what gets persisted is:
>
> session['foo'] = 'updatedfoocontent'
> session['bar'] = 'updatedbarcontent'
>
> I'm using django 1.4 and db-based sessions.
>
> Thanks in advance,
>
> Spork
>
>
The session is not suitable for this sort of partial modification. It is 
serialized and unserialized as a whole, so there is no way to prevent the 
data being "stomped".

You should store the data somewhere else: probably in a model.
--
DR. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d2b019e3-711c-47d2-a1d6-d8283d4bcc63%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


session modification question

2014-01-18 Thread Spork Spork
Hi,

I have a question about what gets persisted when session data gets updated. 
I've read the sessions chapter of the book, and it's not entirely clear to 
me.

Say I have two keys in the session object that I'm manipulating in a view:

view1: request.session['foo'] = 'foocontent'
view1: request.session['bar'] = 'barcontent'
view1: goes off and does something that takes a long, long timer

Meanwhile some other view fires off and changes foo:

view2: request.session['foo'] = 'updateddfoocontent'

Then view2 exits, and the most recent session data gets persisted.

But meanwhile view1 still has the old copy of the session data. Eventually 
it completes whatever it was doing, and updates bar:

view1: request.session['bar'] = 'updatedbarcontent'

Question: when view1 exits and its data gets persisted, does it overwrite 
all of the session data, including stomping on view2's modification of foo? 
If so, how can I ensure that at the end of view1, what gets persisted is:

session['foo'] = 'updatedfoocontent'
session['bar'] = 'updatedbarcontent'

I'm using django 1.4 and db-based sessions.

Thanks in advance,

Spork

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ab990f4a-3714-45b5-9a6c-0595af79d964%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.