Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4703 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a5e9f508ce1ba6afe90fe8da3b453c780b1a7342 1 parent 5c2e83e
Jacob Kaplan-Moss authored March 11, 2007
1  django/contrib/contenttypes/management.py
@@ -7,6 +7,7 @@
7 7
 
8 8
 def create_contenttypes(app, created_models, verbosity=2):
9 9
     from django.contrib.contenttypes.models import ContentType
  10
+    ContentType.objects.clear_cache()
10 11
     app_models = get_models(app)
11 12
     if not app_models:
12 13
         return
10  django/contrib/contenttypes/models.py
@@ -19,6 +19,16 @@ def get_for_model(self, model):
19 19
                 model=key[1], defaults={'name': str(opts.verbose_name)})
20 20
             CONTENT_TYPE_CACHE[key] = ct
21 21
         return ct
  22
+        
  23
+    def clear_cache(self):
  24
+        """
  25
+        Clear out the content-type cache. This needs to happen during database
  26
+        flushes to prevent caching of "stale" content type IDs (see
  27
+        django.contrib.contenttypes.management.create_contenttypes for where
  28
+        this gets called).
  29
+        """
  30
+        global CONTENT_TYPE_CACHE
  31
+        CONTENT_TYPE_CACHE = {}
22 32
 
23 33
 class ContentType(models.Model):
24 34
     name = models.CharField(maxlength=100)

0 notes on commit a5e9f50

Please sign in to comment.
Something went wrong with that request. Please try again.