Failing test code when using contenttypes app.
|Reported by:||oliverandrich||Owned by:||nobody|
|Cc:||oliver.andrich@…, aball@…||Triage Stage:||Accepted|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In a project where I use the django.contrib.contenttypes app, I see errors in almost all my tests involving contenttypes. The error message below is from mysql, but I can also reproduce it for postgresql. sqlite3 seems to be save.
IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (`test_test_content_type_sync_auth_bug/auth_permission`, CONSTRAINT `content_type_id_refs_id_728de91f` FOREIGN KEY (`content_type_id`) REFERENCES `django_content_type` (`id`))')
Seems as some created foreign key constraints aren't satisfied.
For reproduction I created a minimal django project (see the attached zip file). If you run "./manage.py test testapp" inside this project, you will see the error message.
I have tracked down this issue to the call to the flush command in the _pre_setup method of the django.test.TestCase class. Further tracking inside this method showed, that everything works fine until the django.contrib.auth apps post_syncdb signal handlers are called. The strange part about that is, that "./manager.py flush --verbosity=0 --noinput" basically does the same and doesn't cause such problems.
The model in the testapp application has a ForeignKey relationship to the ContentType model as described in http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/. The User model itself has no reverse generic relation is provided, as this is impossible for me with the User model.
I hope this information helps to track that issue, and I also hope I haven't missed anything.
Change History (18)
Changed 7 years ago by oliverandrich
comment:1 Changed 7 years ago by anonymous
- Component changed from Uncategorized to Contrib apps
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Version changed from SVN to 1.0
comment:8 Changed 4 years ago by gabrielhurley
- Component changed from Contrib apps to contrib.contenttypes