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
This commit is contained in:
parent
5c2e83eef5
commit
a5e9f508ce
|
@ -7,6 +7,7 @@ from django.db.models import get_apps, get_models, signals
|
||||||
|
|
||||||
def create_contenttypes(app, created_models, verbosity=2):
|
def create_contenttypes(app, created_models, verbosity=2):
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
ContentType.objects.clear_cache()
|
||||||
app_models = get_models(app)
|
app_models = get_models(app)
|
||||||
if not app_models:
|
if not app_models:
|
||||||
return
|
return
|
||||||
|
|
|
@ -20,6 +20,16 @@ class ContentTypeManager(models.Manager):
|
||||||
CONTENT_TYPE_CACHE[key] = ct
|
CONTENT_TYPE_CACHE[key] = ct
|
||||||
return 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):
|
class ContentType(models.Model):
|
||||||
name = models.CharField(maxlength=100)
|
name = models.CharField(maxlength=100)
|
||||||
app_label = models.CharField(maxlength=100)
|
app_label = models.CharField(maxlength=100)
|
||||||
|
|
Loading…
Reference in New Issue