Skip to content

Commit

Permalink
[1.5.x] Fixed #18978 -- Moved cleanup command to sessions.
Browse files Browse the repository at this point in the history
This removes a dependency of 'core' on 'contrib'.

Backport of 83ba0a9 from master.

This deprecation occurs after the alpha, but it's a prerequisite
for fixing decently #18194 which is a release blocker.
  • Loading branch information
aaugustin committed Oct 27, 2012
1 parent 15ea36d commit b760503
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 11 deletions.
8 changes: 7 additions & 1 deletion django/bin/daily_cleanup.py
Expand Up @@ -7,7 +7,13 @@
sessions at the moment). sessions at the moment).
""" """


import warnings

from django.core import management from django.core import management


if __name__ == "__main__": if __name__ == "__main__":
management.call_command('cleanup') warnings.warn(
"The `daily_cleanup` script has been deprecated "
"in favor of `django-admin.py clearsessions`.",
PendingDeprecationWarning)
management.call_command('clearsessions')
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions django/contrib/sessions/management/commands/clearsessions.py
@@ -0,0 +1,11 @@
from django.core.management.base import NoArgsCommand
from django.utils import timezone

class Command(NoArgsCommand):
help = "Can be run as a cronjob or directly to clean out expired sessions (only with the database backend at the moment)."

def handle_noargs(self, **options):
from django.db import transaction
from django.contrib.sessions.models import Session
Session.objects.filter(expire_date__lt=timezone.now()).delete()
transaction.commit_unless_managed()
16 changes: 8 additions & 8 deletions django/core/management/commands/cleanup.py
@@ -1,11 +1,11 @@
from django.core.management.base import NoArgsCommand import warnings
from django.utils import timezone


class Command(NoArgsCommand): from django.contrib.sessions.management.commands import clearsessions
help = "Can be run as a cronjob or directly to clean out old data from the database (only expired sessions at the moment)."



class Command(clearsessions.Command):
def handle_noargs(self, **options): def handle_noargs(self, **options):
from django.db import transaction warnings.warn(
from django.contrib.sessions.models import Session "The `cleanup` command has been deprecated in favor of `clearsessions`.",
Session.objects.filter(expire_date__lt=timezone.now()).delete() PendingDeprecationWarning)
transaction.commit_unless_managed() super(Command, self).handle_noargs(**options)
5 changes: 5 additions & 0 deletions docs/internals/deprecation.txt
Expand Up @@ -293,6 +293,11 @@ these changes.
* The ``AUTH_PROFILE_MODULE`` setting, and the ``get_profile()`` method on * The ``AUTH_PROFILE_MODULE`` setting, and the ``get_profile()`` method on
the User model, will be removed. the User model, will be removed.


* The ``cleanup`` management command will be removed. It's replaced by
``clearsessions``.

* The ``daily_cleanup.py`` script will be removed.

2.0 2.0
--- ---


Expand Down
15 changes: 15 additions & 0 deletions docs/ref/django-admin.txt
Expand Up @@ -96,6 +96,9 @@ cleanup
Can be run as a cronjob or directly to clean out old data from the database Can be run as a cronjob or directly to clean out old data from the database
(only expired sessions at the moment). (only expired sessions at the moment).


.. versionchanged:: 1.5
:djadmin:`cleanup` is deprecated. Use :djadmin:`clearsessions` instead.

compilemessages compilemessages
--------------- ---------------


Expand Down Expand Up @@ -1187,6 +1190,18 @@ This command is only available if :doc:`GeoDjango </ref/contrib/gis/index>`
Please refer to its :djadmin:`description <ogrinspect>` in the GeoDjango Please refer to its :djadmin:`description <ogrinspect>` in the GeoDjango
documentation. documentation.


``django.contrib.sessions``
---------------------------

clearsessions
~~~~~~~~~~~~~~~

.. django-admin:: clearsessions

Can be run as a cron job or directly to clean out expired sessions.

This is only supported by the database backend at the moment.

``django.contrib.sitemaps`` ``django.contrib.sitemaps``
--------------------------- ---------------------------


Expand Down
13 changes: 12 additions & 1 deletion docs/releases/1.5.txt
Expand Up @@ -613,11 +613,22 @@ Define a ``__str__`` method and apply the
The :func:`~django.utils.itercompat.product` function has been deprecated. Use The :func:`~django.utils.itercompat.product` function has been deprecated. Use
the built-in :func:`itertools.product` instead. the built-in :func:`itertools.product` instead.



``django.utils.markup`` ``django.utils.markup``
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~


The markup contrib module has been deprecated and will follow an accelerated The markup contrib module has been deprecated and will follow an accelerated
deprecation schedule. Direct use of python markup libraries or 3rd party tag deprecation schedule. Direct use of python markup libraries or 3rd party tag
libraries is preferred to Django maintaining this functionality in the libraries is preferred to Django maintaining this functionality in the
framework. framework.

``cleanup`` management command
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The :djadmin:`cleanup` management command has been deprecated and replaced by
:djadmin:`clearsessions`.

``daily_cleanup.py`` script
~~~~~~~~~~~~~~~~~~~~~~~~~~~

The undocumented ``daily_cleanup.py`` script has been deprecated. Use the
:djadmin:`clearsessions` management command instead.
2 changes: 1 addition & 1 deletion docs/topics/http/sessions.txt
Expand Up @@ -460,7 +460,7 @@ table. Django updates this row each time the session data changes. If the user
logs out manually, Django deletes the row. But if the user does *not* log out, logs out manually, Django deletes the row. But if the user does *not* log out,
the row never gets deleted. the row never gets deleted.


Django provides a sample clean-up script: ``django-admin.py cleanup``. Django provides a sample clean-up script: ``django-admin.py clearsessions``.
That script deletes any session in the session table whose ``expire_date`` is That script deletes any session in the session table whose ``expire_date`` is
in the past -- but your application may have different requirements. in the past -- but your application may have different requirements.


Expand Down

0 comments on commit b760503

Please sign in to comment.