#9227: The modeltests/serializer unit test case fails due to missing author
record
with id=4
-------------------------------------------------------------+--------------
Reporter: egenix_viktor <[EMAIL PROTECTED]> | Owner:
nobody
Status: new | Milestone:
Component: Database layer (models, ORM) | Version:
1.0
Keywords: unit test foreign key constraint IntegrityError | Stage:
Unreviewed
Has_patch: 0 |
-------------------------------------------------------------+--------------
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.
--
Ticket URL: <http://code.djangoproject.com/ticket/9227>
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
-~----------~----~----~----~------~----~------~--~---