{"action":"created","issue":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2996","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2996/labels{/name}","comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2996/comments","events_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2996/events","html_url":"https://github.com/tomchristie/django-rest-framework/issues/2996","id":83748364,"number":2996,"title":"Unique constraint prevents nested serializers from updating","user":{"login":"xordoquy","id":2340654,"avatar_url":"https://avatars.githubusercontent.com/u/2340654?v=3","gravatar_id":"","url":"https://api.github.com/users/xordoquy","html_url":"https://github.com/xordoquy","followers_url":"https://api.github.com/users/xordoquy/followers","following_url":"https://api.github.com/users/xordoquy/following{/other_user}","gists_url":"https://api.github.com/users/xordoquy/gists{/gist_id}","starred_url":"https://api.github.com/users/xordoquy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xordoquy/subscriptions","organizations_url":"https://api.github.com/users/xordoquy/orgs","repos_url":"https://api.github.com/users/xordoquy/repos","events_url":"https://api.github.com/users/xordoquy/events{/privacy}","received_events_url":"https://api.github.com/users/xordoquy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/labels/Needs%20design%20decision","name":"Needs design decision","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-06-01T23:45:10Z","updated_at":"2015-10-26T18:40:54Z","closed_at":null,"body":"If you have a nested serializer which model does have a unique constraint on a field you're not able to reference an existing instance.\r\n\r\n```\r\nclass Task(serializers.ModelSerializer):\r\n    class Meta:\r\n        model = models.Task\r\n        fields = ('id', 'name')\r\n\r\n\r\nclass Category(serializers.ModelSerializer):\r\n    tasks = Task(many=True)\r\n    class Meta:\r\n        model = models.Category\r\n        fields = ('id', 'name', 'tasks')\r\n```\r\n\r\nLet's say I created a category & task which I'm updating with the very same data they already have:\r\n\r\n```\r\nc = Category(data={\"id\": 1, \"name\": \"Django\", \"tasks\": [{\"id\": 1, \"name\": \"Demo\", \"owner\": \"admin\"}]})\r\nc.is_valid()  # Returns False\r\nc.errors  # Returns {'tasks': [{'name': ['This field must be unique.']}]}\r\n```\r\n\r\nThe point is, `name` remains unique because it matches its own `id` \r\n"},"comment":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/comments/151243432","html_url":"https://github.com/tomchristie/django-rest-framework/issues/2996#issuecomment-151243432","issue_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2996","id":151243432,"user":{"login":"ankitml","id":573824,"avatar_url":"https://avatars.githubusercontent.com/u/573824?v=3","gravatar_id":"","url":"https://api.github.com/users/ankitml","html_url":"https://github.com/ankitml","followers_url":"https://api.github.com/users/ankitml/followers","following_url":"https://api.github.com/users/ankitml/following{/other_user}","gists_url":"https://api.github.com/users/ankitml/gists{/gist_id}","starred_url":"https://api.github.com/users/ankitml/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ankitml/subscriptions","organizations_url":"https://api.github.com/users/ankitml/orgs","repos_url":"https://api.github.com/users/ankitml/repos","events_url":"https://api.github.com/users/ankitml/events{/privacy}","received_events_url":"https://api.github.com/users/ankitml/received_events","type":"User","site_admin":false},"created_at":"2015-10-26T18:40:54Z","updated_at":"2015-10-26T18:40:54Z","body":"So what is the way out? This to me seems like a major limitation. \r\n\r\n1. Writing custom non-model serializer. - Almost all my endpoints would have custom serializers then. \r\n2. Ignoring 'id' from 'to_internal_value' method.* - Might run into trouble later on because of this. \r\n3. Any way to use model serializer but change the validation rule for nested serializr? some sort of mixin.. This would be an ideal way, not sure how to do it. \r\n\r\n\r\n\r\n* check issue no 2403. "}}