Hi Guys, 

I am using sessions in my webapp, and don't want to use a db/file backends 
as my device
has small storage, so, using signed_cookies backend, I need to store and 
modify per-session data
across places and use the session_key to lookup, modify and then save. But 
every save creates a 
new session, so, the change isn't propagated to other views. 

func_view(request)
   start_async_oper(func_non_view, args=request.session)
   # session is created in another view
   request.session.data = 1

func_view2(request):
   check (request.session.data == 2)

func_non_view(session):
  session = SessionStore(session_key=session.session_key)
  session.data = 2
  session.save()

Session_key is passed from view to non-view and then I am using 
Sessionstore(session_key) to 
lookup the session from non-view, and then after modification normally do a 
save() and from the
view, I read updated session values. 

This logic works if I use either a db/file backend. 
Also confirmed this behavior by looking at the save() function of various 
backends.
https://github.com/django/django/blob/master/django/contrib/sessions/backends/signed_cookies.py#L41

If I just change the session data (not from a view), but don't do a save I 
can see that the session_key hasn't changed
but obviously the change isn't reflected. 

The Django version is 1.11 (Default Ubuntu18.04, cannot update) but looks 
like the signed_cookies code hasn't changed.

Looks like a bug to me? am I missing anything? I can move the session 
update to a view and use some globals but 
this design keeps it simple by storing the data in the session.

Any help is appreciated.

Thanks.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/abca3930-31e5-4de2-8200-1ddab80b8734o%40googlegroups.com.

Reply via email to