tomchristie/django-rest-framework — pull request #1902 by mjumbewu (2014-09-24 17:07:22+00:00)
Title: Remove nested associations before adding new ones, to avoid collisions

E.g., say you have a `unique_together` set of fields `('parent', 'slug')`, and a model that initially serializes to this data:

[
{
"id": 1,
"parent": 1,
"slug": "first",
"text": "This is the initial version of the first element"
},
{
"id": 2,
"parent": 1,
"slug": "second",
"text": "This is the second element"
}
]

Then in your client application you delete the first element and replace it with a new one. The data that you pass up to the API will be something like:

[
{
"parent": 1,
"slug": "first",
"text": "This is a new version of the first element"
},
{
"id": 2,
"parent": 1,
"slug": "second",
"text": "This is the second element"
}
]

This should be valid, but will cause an integrity error when deserialized because it will try to create the new element before deleting the old one.