toastdriven/django-tastypie — pull request #589 by maraujop (2012-07-30 10:50:45+00:00)
Title: Fixing partial PUTS on resources with m2m relations

* This allows partial PUTs to work with resources that contain m2m relations, whose data is not provided within the PUT request.

* It also avoids erasing `ManyToManyFields` with a `through` table, which don't have an add method by default. Most likely we want to LOG error this case, so that the coder can know what's going on, but I haven't added the logging lines.

I believe that `obj_update` and other methods should be handled in a transaction and related fields only saved when necessary. I will try to explain some error cases I can foresee.

### 500 when it's a 200

For example, if I'm sending a PUT (not a partial PUT, which are not supported by the official REST standard), providing changes on some booleans of a resource that contains m2ms.

The boolean changes get saved before m2ms. After that m2ms get hydrated and saved no matter if they changed or not, which could cause an exception and Tastypie would return a 500, which is not true, as they request succeeded.

m2ms should only be saved when changes happen.

### Inconsistent state

If I provide changes for booleans and also an m2m field. Booleans could be saved, m2m changes fail. Tastypie returns a 500 and the database is left in a inconsistent state, as part of my changes have been saved and others not, right?

Cheers, thanks
Miguel