Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Reverted [14563] because it introduced a dependency from core on a co…

…ntrib app (contenttypes). Fixes #16283, Refs #3055. Thanks TheRoSS for the report and Aymeric Augustin for finding the problem.

This caused models shipped with some contrib apps to pollute the namespace when user's apps had the same name (e.g. auth, sites), even when these contrib apps weren't installed.

This undesired loading of contrib apps happened when model validation was executed, for example when running management commands that set or inherit `requires_model_validation=True`:
cleanup, dumpdata, flush, loaddata, reset, runfcgi, sql, sqlall, sqlclear, sqlcustom, sqlflush, sqlindexes, sqlinitialdata, sqlreset, sqlsequencereset, syncdb, createsuperusers, ping_google, collectstatic, findstatic.

This could also cause hard to diagnose problems e.g. when performing reverse URL resolving.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16493 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1d270ac8a34b9a1f562d2e46411121499caa6e41 1 parent d138906
Ramiro Morales authored July 03, 2011
7  django/core/management/validation.py
... ...
@@ -1,6 +1,5 @@
1 1
 import sys
2 2
 
3  
-from django.contrib.contenttypes.generic import GenericForeignKey, GenericRelation
4 3
 from django.core.management.color import color_style
5 4
 from django.utils.itercompat import is_iterable
6 5
 
@@ -235,12 +234,6 @@ def get_validation_errors(outfile, app=None):
235 234
                 e.add(opts, "'%s' specifies an m2m relation through model %s, "
236 235
                     "which has not been installed" % (f.name, f.rel.through)
237 236
                 )
238  
-            elif isinstance(f, GenericRelation):
239  
-                if not any([isinstance(vfield, GenericForeignKey) for vfield in f.rel.to._meta.virtual_fields]):
240  
-                    e.add(opts, "Model '%s' must have a GenericForeignKey in "
241  
-                        "order to create a GenericRelation that points to it."
242  
-                        % f.rel.to.__name__
243  
-                    )
244 237
 
245 238
             rel_opts = f.rel.to._meta
246 239
             rel_name = RelatedObject(f.rel.to, cls, f).get_accessor_name()
17  tests/modeltests/invalid_models/models.py
@@ -4,7 +4,6 @@
4 4
 This example exists purely to point out errors in models.
5 5
 """
6 6
 
7  
-from django.contrib.contenttypes import generic
8 7
 from django.db import models
9 8
 
10 9
 class FieldErrors(models.Model):
@@ -219,21 +218,6 @@ class InvalidSetNull(models.Model):
219 218
 class InvalidSetDefault(models.Model):
220 219
     fk = models.ForeignKey('self', on_delete=models.SET_DEFAULT)
221 220
 
222  
-class Tag(models.Model):
223  
-   name = models.CharField("name", max_length=20)
224  
-
225  
-class TaggedObject(models.Model):
226  
-   object_id = models.PositiveIntegerField("Object ID")
227  
-   tag = models.ForeignKey(Tag)
228  
-   content_object = generic.GenericForeignKey()
229  
-
230  
-class UserTaggedObject(models.Model):
231  
-   object_tag = models.ForeignKey(TaggedObject)
232  
-
233  
-class ArticleAttachment(models.Model):
234  
-   tags = generic.GenericRelation(TaggedObject)
235  
-   user_tags = generic.GenericRelation(UserTaggedObject)
236  
-
237 221
 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute that is a positive integer.
238 222
 invalid_models.fielderrors: "charfield2": CharFields require a "max_length" attribute that is a positive integer.
239 223
 invalid_models.fielderrors: "charfield3": CharFields require a "max_length" attribute that is a positive integer.
@@ -343,5 +327,4 @@ class ArticleAttachment(models.Model):
343 327
 invalid_models.nonexistingorderingwithsingleunderscore: "ordering" refers to "does_not_exist", a field that doesn't exist.
344 328
 invalid_models.invalidsetnull: 'fk' specifies on_delete=SET_NULL, but cannot be null.
345 329
 invalid_models.invalidsetdefault: 'fk' specifies on_delete=SET_DEFAULT, but has no default value.
346  
-invalid_models.articleattachment: Model 'UserTaggedObject' must have a GenericForeignKey in order to create a GenericRelation that points to it.
347 330
 """

0 notes on commit 1d270ac

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