Some Doubts on Session Expiries

12 views
Skip to first unread message

vineeth sagar

unread,
Jul 25, 2018, 3:12:54 PM7/25/18
to Django users
Hi,

I have been going crazy for the past few days trying to understand sessions, my settings.py file as the following,

SESSION_SAVE_EVERY_REQUEST=True
SESSION_COOKIE_AGE=2*60

Now whenever a request is initiated shoudn't the expiry date of the cookie i.e the one that holds the session id ,doubled i.e become four minutes. This is not happening and I am using chrome. Is this normal? I don't think so,from the amount of stackoverflow posts on this discussion.

Now towards the second part of the question, Forget about what I have said till now, now my settings.py contains only this.

SESSION_EXPIRE_AT_BROWSER_CLOSE=True.

A user "admin" has initiated a request, done some work closed his browser, session cookie holding the session id has expired and that's wonderful as expected. 

Now If I run this snippet,

from django.contrib.sessions.models import Session
from django.utils import timzone

sessions = Sessions.objects.filter(expire_date__gte=timezone.now())

The above queryset has the session of the admin user, I am confused is this expected behavior? Can someone please address the queries for me.

Thank you

regards

Melvyn Sopacua

unread,
Jul 25, 2018, 4:56:13 PM7/25/18
to django...@googlegroups.com
On woensdag 25 juli 2018 21:05:27 CEST vineeth sagar wrote:
> Hi,
>
> I have been going crazy for the past few days trying to understand
> sessions, my settings.py file as the following,
>
> SESSION_SAVE_EVERY_REQUEST=True
> SESSION_COOKIE_AGE=2*60
>
> Now whenever a request is initiated shoudn't the expiry date of the cookie
> i.e the one that holds the session id ,doubled i.e become four minutes.

No. It stays 2 minutes. But two minutes from the last time it was used. If you
were too late or have a clock out of sync, then you'll never get the update to
the next two minutes.


> A user "admin" has initiated a request, done some work closed his browser,
> session cookie holding the session id has expired and that's wonderful as
> expected.
>
> Now If I run this snippet,
>
> from django.contrib.sessions.models import Session
> from django.utils import timzone
>
> sessions = Sessions.objects.filter(expire_date__gte=timezone.now())
>
> The above queryset has the session of the admin user, I am confused is this
> expected behavior? Can someone please address the queries for me.

That's just fine, because the browser will not send the cookie, so the session
is never looked for. Once the date expires, it will be garbage collected.

--
Melvyn Sopacua


Reply all
Reply to author
Forward
0 new messages