Django

Code

Ticket #4427 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

daily_cleanup.py should use database API

Reported by: nick.lane.au@gmail.com Assigned to: adrian
Milestone: Component: Tools
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

daily_cleanup.patch (0.5 kB) - added by nick.lane.au@gmail.com on 05/30/07 00:11:14.
Patch to use database API for daily_cleanup
daily_cleanup.2.patch (0.8 kB) - added by nick.lane.au@gmail.com on 05/30/07 00:16:46.
Unified diff.
daily_cleanup.3.patch (0.8 kB) - added by nick.lane.au@gmail.com on 05/30/07 00:18:42.
The right way round this time…

Change History

05/30/07 00:11:14 changed by nick.lane.au@gmail.com

  • attachment daily_cleanup.patch added.

Patch to use database API for daily_cleanup

05/30/07 00:16:46 changed by nick.lane.au@gmail.com

  • attachment daily_cleanup.2.patch added.

Unified diff.

05/30/07 00:18:42 changed by nick.lane.au@gmail.com

  • attachment daily_cleanup.3.patch added.

The right way round this time...

05/30/07 00:20:01 changed by nick.lane.au@gmail.com

  • needs_better_patch changed.
  • summary changed from daily_cleanup.py should use database API to [patch] daily_cleanup.py should use database API.
  • needs_tests changed.
  • needs_docs changed.

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)

05/30/07 04:06:58 changed by Simon G. <dev@simon.net.nz>

  • owner changed from jacob to adrian.
  • has_patch set to 1.
  • summary changed from [patch] daily_cleanup.py should use database API to daily_cleanup.py should use database API.
  • component changed from Uncategorized to Tools.
  • 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.

06/01/07 04:46:57 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #4427 (daily_cleanup.py should use database API)




Change Properties
Action