Opened 9 years ago

Closed 9 years ago

#24819 closed Bug (invalid)

clearsessions deletes sessions that expire in the next hour

Reported by: Ghanshyam Rajpurohit Owned by: nobody
Component: contrib.sessions Version: 1.8
Severity: Normal Keywords: Session, clearsessions
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

[clearsessions]https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-

As while using the Commands provided for session as to clean out expired sessions.

python manage.py clearsessions

I have used the

SESSION_ENGINE = "django.contrib.sessions.backends.db"

As to generate This bug.

list all session object. in the db.

from django.contrib.sessions.models import Session
Session.objects.all()

take any one of the key from list.

from django.contrib.sessions.models import Session
import datetime
sessgo = Session.objects.get(pk='session primary')
sessgo.expire_date = sessgo.expire_date.replace(datetime.datetime.now().year, datetime.datetime.now().month,datetime.datetime.now().day, datetime.datetime.now().hour+1, datetime.datetime.now().minute)
sessgo.save()
sessgo.expire_date

now just run.
python manage.py clearsessions

and list again:

Session.objects.all()

you will see the Session has been deleted even it has expire time after 1 hours.

It works fine with year,month,day but it gets clear for the hour and minutes

In above step I have done any wrong please let me know.

Change History (1)

comment:1 by Tim Graham, 9 years ago

Resolution: invalid
Status: newclosed
Summary: Commands provided for clearsessions. It also clears the the last hour and minute sessionclearsessions deletes sessions that expire in the next hour

The query that clearsessions runs is Session.objects.filter(expire_date__lt=timezone.now()).delete(). I guess the timezone offset may account for the behavior you are seeing. Please reopen with more details if not. Thanks!

Note: See TracTickets for help on using tickets.
Back to Top