diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2007-03-11 16:06:08 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2007-03-11 16:06:08 +0000 |
| commit | a5e9f508ce1ba6afe90fe8da3b453c780b1a7342 (patch) | |
| tree | 7c68347f02f3610d91c69f0d5465c9e79eddb027 | |
| parent | 5c2e83eef59c9591d1b5c65e5f265fc80271f283 (diff) | |
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
| -rw-r--r-- | django/contrib/contenttypes/management.py | 1 | ||||
| -rw-r--r-- | django/contrib/contenttypes/models.py | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py index f492f54303..3572d93049 100644 --- a/django/contrib/contenttypes/management.py +++ b/django/contrib/contenttypes/management.py @@ -7,6 +7,7 @@ from django.db.models import get_apps, get_models, signals 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 diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py index 3384134cb2..0a5e68f37e 100644 --- a/django/contrib/contenttypes/models.py +++ b/django/contrib/contenttypes/models.py @@ -19,6 +19,16 @@ class ContentTypeManager(models.Manager): 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) |
