From 1fc0077a95aff89fde16a8496884d2ca2c4de7c9 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sun, 22 Jun 2008 06:50:25 +0000 Subject: [PATCH] Fixed #7517 -- Added code to remove Sites from the site cache when they are deleted. Thanks to Marc Fargas for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7724 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/sites/models.py | 9 +++++++++ django/contrib/sites/tests.py | 13 +++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 django/contrib/sites/tests.py diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py index fb6d0a2b1e9..c928a4e8522 100644 --- a/django/contrib/sites/models.py +++ b/django/contrib/sites/models.py @@ -44,6 +44,15 @@ class Site(models.Model): def __unicode__(self): return self.domain + def delete(self): + pk = self.pk + super(Site, self).delete() + try: + del(SITE_CACHE[pk]) + except KeyError: + pass + + class RequestSite(object): """ A class that shares the primary interface of Site (i.e., it has diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py new file mode 100644 index 00000000000..d2ec331eca5 --- /dev/null +++ b/django/contrib/sites/tests.py @@ -0,0 +1,13 @@ +""" +>>> # Make sure that get_current() does not return a deleted Site object. +>>> from django.contrib.sites.models import Site +>>> s = Site.objects.get_current() +>>> s + + +>>> s.delete() +>>> Site.objects.get_current() +Traceback (most recent call last): +... +DoesNotExist: Site matching query does not exist. +"""