Re: Inconsistent Django test results depending upon how the test is called in Django 1.5.1 running on Python 2.7.4
Hi Russ,
Thanks for your detailed response, deserving of this detailed investigation:
I eventually found that it is the simple declaration of a model within the test suites that is causing the problem:
django.contrib.contents.tests causes the problem - even if I removed all of the tests and just imported the file:
I copied and pared the file down to this which still causes the error:
from django.db import models class ConcreteModel(models.Model): name = models.CharField(max_length=10) class ProxyModel(ConcreteModel): class Meta: proxy = TrueIf I remove the ProxyModel class the error changes and becomes a recursion depth error.
Renaming the classes does not get rid of the error (and the class names are not used in my apps).
The infinite recursion problem feels somehow related. My models do do something unusual: Much of the application revolves around models belonging to a company so, for convenience, all models have a company property that returns the company that owns them - it often does this by referencing objects on it. In the case of a company, the company property returns self. In the case of a note (the model where we're getting this problem), the content_object is a company and the note's company method accesses its content_object company attribute:
class Note(TimeStampedModel): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') ... @property def company(self): return self.content_object.company class Company(BaseModel, ModelWithRandomisedToken): ... @property def company(self): return selfI think this is progress. Declaring ANY model class within the test suite causes the infinite recursion issue on the access. So my theory is that something in the django caching somewhere is getting partly updated when the model is declared but not fully sorted so the caches are broken with respect to content types. This has two symptoms - object references being None and infinite recursion, depending upon how the error gets encountered.
I'm guessing that there is some 'tidying up' of content types after all the models are imported that does not get done for a model arbitrarily defined in the test suite.
Does it sound like I am going in the right direction?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJxq84-vBqpGHg7YbEMPtfbofrtOb2ZWHLZD5%3Dh_sOr1Le5FTg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home