Author: jacob
Date: 2007-03-11 10:06:08 -0600 (Sun, 11 Mar 2007)
New Revision: 4703
Modified:
django/trunk/django/contrib/contenttypes/management.py
django/trunk/django/contrib/contenttypes/models.py
Log:
Added {{{ContentType.objects.clear_cache()}}} which clears the lookup cache.
This needs to be called at syncdb time to avoid "stale" content-type IDs after
the database gets flushed during unit tests.
Modified: django/trunk/django/contrib/contenttypes/management.py
===================================================================
--- django/trunk/django/contrib/contenttypes/management.py 2007-03-11
10:37:33 UTC (rev 4702)
+++ django/trunk/django/contrib/contenttypes/management.py 2007-03-11
16:06:08 UTC (rev 4703)
@@ -7,6 +7,7 @@
def create_contenttypes(app, created_models, verbosity=2):
from django.contrib.contenttypes.models import ContentType
+ ContentType.objects.clear_cache()
app_models = get_models(app)
if not app_models:
return
Modified: django/trunk/django/contrib/contenttypes/models.py
===================================================================
--- django/trunk/django/contrib/contenttypes/models.py 2007-03-11 10:37:33 UTC
(rev 4702)
+++ django/trunk/django/contrib/contenttypes/models.py 2007-03-11 16:06:08 UTC
(rev 4703)
@@ -19,6 +19,16 @@
model=key[1], defaults={'name': str(opts.verbose_name)})
CONTENT_TYPE_CACHE[key] = ct
return ct
+
+ def clear_cache(self):
+ """
+ Clear out the content-type cache. This needs to happen during database
+ flushes to prevent caching of "stale" content type IDs (see
+ django.contrib.contenttypes.management.create_contenttypes for where
+ this gets called).
+ """
+ global CONTENT_TYPE_CACHE
+ CONTENT_TYPE_CACHE = {}
class ContentType(models.Model):
name = models.CharField(maxlength=100)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---