Opened 15 years ago

Closed 13 years ago

#13016 closed Bug (duplicate)

Invalid ForeignKey ids in fixtures do not cause any error messages

Reported by: Art <artem.skvira@…> Owned by: nobody
Component: Testing framework Version: 1.1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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).


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.

Backend is Postgresql 8.3.


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)




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     }



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)


Change History (5)

comment:1 by Russell Keith-Magee, 15 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Mikhail Korobov, 14 years ago

I found current behaviour very useful because it means I'm not obligated to write fixtures for all relations if I don't want to. Sometimes there is no need for related objects, only id are interesting. Less fixtures to write and maintain, less fixtures to load, faster tests. So in my opinion this proposal is a backward-incompatible feature request. Am I missing something?

comment:3 by Luke Plant, 14 years ago

Type: Bug

comment:4 by Luke Plant, 14 years ago

Severity: Normal

comment:5 by Ramiro Morales, 13 years ago

Easy pickings: unset
Resolution: duplicate
Status: newclosed
UI/UX: unset

I'm going to close this as a duplicate of #11665.

Note: See TracTickets for help on using tickets.
Back to Top