{"action":"opened","issue":{"url":"https://api.github.com/repos/beda-software/drf-writable-nested/issues/58","repository_url":"https://api.github.com/repos/beda-software/drf-writable-nested","labels_url":"https://api.github.com/repos/beda-software/drf-writable-nested/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/beda-software/drf-writable-nested/issues/58/comments","events_url":"https://api.github.com/repos/beda-software/drf-writable-nested/issues/58/events","html_url":"https://github.com/beda-software/drf-writable-nested/issues/58","id":386943341,"node_id":"MDU6SXNzdWUzODY5NDMzNDE=","number":58,"title":"Multipart PATCH requests cause m2m relation to be deleted","user":{"login":"bjornpost","id":48628,"node_id":"MDQ6VXNlcjQ4NjI4","avatar_url":"https://avatars3.githubusercontent.com/u/48628?v=4","gravatar_id":"","url":"https://api.github.com/users/bjornpost","html_url":"https://github.com/bjornpost","followers_url":"https://api.github.com/users/bjornpost/followers","following_url":"https://api.github.com/users/bjornpost/following{/other_user}","gists_url":"https://api.github.com/users/bjornpost/gists{/gist_id}","starred_url":"https://api.github.com/users/bjornpost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjornpost/subscriptions","organizations_url":"https://api.github.com/users/bjornpost/orgs","repos_url":"https://api.github.com/users/bjornpost/repos","events_url":"https://api.github.com/users/bjornpost/events{/privacy}","received_events_url":"https://api.github.com/users/bjornpost/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-03T18:19:30Z","updated_at":"2018-12-03T18:19:30Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nToday I ran into this issue where the `Post<>Author` m2m relation was deleted when (partially) updating `Post.title` via a multipart form patch request. These are my findings so far:\r\n\r\nMy serializers (simplified):\r\n\r\n```\r\nclass AuthorSerializer(serializers.ModelSerializer):\r\n    class Meta:\r\n        fields = ('id',)\r\n\r\nclass PostSerializer(WritableNestedModelSerializer):\r\n    authors = AuthorSerializer(many=True)\r\n    ...\r\n\r\n    class Meta:\r\n        fields = ('title', 'authors',)\r\n```\r\n\r\nWhen updating via the shell, all seems fine, authors relation is not removed:\r\n\r\n```\r\n>>> post = Post.objects.get(pk=9)\r\n>>> serializer = PostSerializer(post, data={'title':'my title'}, partial=True)\r\n>>> serializer.update(post, {'title':'my title'})\r\n<Post: my title>\r\n>>> serializer.is_valid()\r\nTrue\r\n>>> serializer.data\r\n{'id': 9, 'title': 'my title', ... 'authors': [OrderedDict([('id', 3), ...])],}\r\n```\r\n\r\nBut, when I'm updating the same object via a multi part form request, the `Post<>Author` relationship is removed on update:\r\n\r\n```\r\ncurl --request PATCH \\\r\n  --url http://... \\\r\n  --form 'title=my title'\r\n\r\n{\r\n  \"id\": 9,\r\n  \"title\": \"my title\",\r\n  \"authors\": [], <---\r\n  ...\r\n```\r\n\r\nI'm happy to create a PR that fixes this issue, but I need some direction on how/where to fix this issue.\r\n\r\nRelated: #30"}}
{"actor":{"display_login":"bjornpost"}}