Opened 18 years ago

Closed 18 years ago

#4427 closed (fixed)

daily_cleanup.py should use database API

Reported by: nick.lane.au@… Owned by: Adrian Holovaty
Component: Tools Version: dev
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The django/bin/daily_cleanup.py script currently uses custom SQL to delete expired session objects. I think it would be neater to use the database API to bulk delete the query set.

For example:

cursor = connection.cursor()
cursor.execute("DELETE FROM %s WHERE %s < NOW()" % \
    (backend.quote_name('django_session'), backend.quote_name('expire_date')))

would become:

Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()

This also has the additional benefit of working in SQLite, whereas with the custom SQL I get the error:
sqlite3.OperationalError: no such function: NOW

Attachments (3)

daily_cleanup.patch (542 bytes ) - added by nick.lane.au@… 18 years ago.
Patch to use database API for daily_cleanup
daily_cleanup.2.patch (850 bytes ) - added by nick.lane.au@… 18 years ago.
Unified diff.
daily_cleanup.3.patch (850 bytes ) - added by nick.lane.au@… 18 years ago.
The right way round this time…

Download all attachments as: .zip

Change History (6)

by nick.lane.au@…, 18 years ago

Attachment: daily_cleanup.patch added

Patch to use database API for daily_cleanup

by nick.lane.au@…, 18 years ago

Attachment: daily_cleanup.2.patch added

Unified diff.

by nick.lane.au@…, 18 years ago

Attachment: daily_cleanup.3.patch added

The right way round this time...

comment:1 by nick.lane.au@…, 18 years ago

Summary: daily_cleanup.py should use database API[patch] daily_cleanup.py should use database API

Sorry about the first 2 patches.. I have no way to access subversion servers from where I am so I had to create the patch manually (and messed up twice doing so)

comment:2 by Simon G. <dev@…>, 18 years ago

Component: UncategorizedTools
Has patch: set
Owner: changed from Jacob to Adrian Holovaty
Summary: [patch] daily_cleanup.py should use database APIdaily_cleanup.py should use database API
Triage Stage: UnreviewedReady for checkin

This seems to me to be a fairly sensible choice, and it does fix a bug with SQLite.

comment:3 by Malcolm Tredinnick, 18 years ago

Resolution: fixed
Status: newclosed

(In [5403]) Fixed #4427 -- Ported daily_cleanup.py to use model API for greater
portability. Thanks, nick.lane.au@….

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