#13016: Invalid ForeignKey ids in fixtures do not cause any error messages
--------------------------------------------+-------------------------------
Reporter: Art <[email protected]> | Owner: nobody
Status: new | Milestone:
Component: Testing framework | Version: 1.1
Keywords: | Stage: Unreviewed
Has_patch: 0 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
--------------------------------------------+-------------------------------
When referencing a non-existing entity instance in fixtures for ForeignKey
relationship no error message is thrown in test runner mode (./manage.py
test). Please note below how in fixtures instance of Parent contains
invalid ID for Child object (2 instead of 1).
[[BR]]
[[BR]]
This seems to be related to "always opened transaction" natures of tests,
because if I run ./manage.py testserver data.json I actually get an
exception thrown.
[[BR]]
Backend is Postgresql 8.3.
[[BR]]
[[BR]]
Model:
{{{
5 class Parent(models.Model):
6 child = models.ForeignKey('Child')
7
8 class Child(models.Model):
9 name = models.CharField(default='some name', max_length=100)
}}}
[[BR]]
[[BR]]
Fixture (data.json):
{{{
352 {
353 "pk": 1,
354 "model": "testapp.parent",
355 "fields": {
356 "child": 2
357 }
358 },
359 {
360 "pk": 1,
361 "model": "testapp.child",
362 "fields": {
363 "name": "child"
364 }
365 }
}}}
[[BR]]
[[BR]]
Test:
{{{
5 class SimpleTest(TestCase):
6
7 fixtures = ['data.json']
8
9 def test_data(self):
10 self.assertEqual(len(models.Parent.objects.all()), 1)
11 self.assertEqual(len(models.Child.objects.all()), 1)
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/13016>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.