Code

Opened 7 years ago

Closed 7 years ago

#4427 closed (fixed)

daily_cleanup.py should use database API

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

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@… 7 years ago.
Patch to use database API for daily_cleanup
daily_cleanup.2.patch (850 bytes) - added by nick.lane.au@… 7 years ago.
Unified diff.
daily_cleanup.3.patch (850 bytes) - added by nick.lane.au@… 7 years ago.
The right way round this time…

Download all attachments as: .zip

Change History (6)

Changed 7 years ago by nick.lane.au@…

Patch to use database API for daily_cleanup

Changed 7 years ago by nick.lane.au@…

Unified diff.

Changed 7 years ago by nick.lane.au@…

The right way round this time...

comment:1 Changed 7 years ago by nick.lane.au@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from daily_cleanup.py should use database API to [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 Changed 7 years ago by Simon G. <dev@…>

  • Component changed from Uncategorized to Tools
  • Has patch set
  • Owner changed from jacob to adrian
  • Summary changed from [patch] daily_cleanup.py should use database API to daily_cleanup.py should use database API
  • Triage Stage changed from Unreviewed to Ready for checkin

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

comment:3 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.