Monday, January 20, 2014

Re: session modification question

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+unsubscribe@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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate