﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
9227	The modeltests/serializer unit test case fails due to missing author record with id=4	egenix_viktor <viktor@…>	nobody	"There is the following test case in modeltests.serializers:

{{{
for obj in serializers.deserialize(""json"", json):
    obj.save()
}}}

JSON data (split to multiple lines by hand):

{{{
[{""pk"": 3, ""model"": ""serializers.article"", ""fields"": {
        ""headline"": ""Forward references pose no problem"",
        ""pub_date"": ""2006-06-16 15:00:00"",
        ""categories"": [4, 1],
        ""author"": 4}},
 {""pk"": 4, ""model"": ""serializers.category"", ""fields"": {
        ""name"": ""Reference""}},
 {""pk"": 4, ""model"": ""serializers.author"", ""fields"": {
        ""name"": ""Agnes""}}
]
}}}

It generates SQL like the following to insert the first record (actual SQL depends on the backend, but that's not relevant to the problem):

{{{
INSERT INTO serializers_article
    (id, author_id, headline, pub_date)
VALUES (%s, %s, %s, %s);
}}}

Actual parameters passed:

(3, 4, u'Forward references pose no problem', u'2006-06-16 15:00:00')

There is a foreign key constraint for serializers_article.author_id pointing to serializers_author.id. The above SQL tries to insert author_id = 4, but there is no serializers_author record with id = 4. Since there is only 3 authors inserted before, so it is normal that no author exists with id = 4. It causes IntegrityError to be raised if the database server enforces foreign key constraints, otherwise this bug can left unnoticed.

'''NOTE:''' The unit test passes without error when using SQLite, since foreign key constaints are note enforced. You need to test with a backend that enforces foreign key constraints to reproduce this bug."		closed	Database layer (models, ORM)	1.0		invalid	unit test foreign key constraint IntegrityError		Unreviewed	0	0	0	0	0	0
