Saturday, January 18, 2014

Re: session modification question

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+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/d2b019e3-711c-47d2-a1d6-d8283d4bcc63%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