{"action":"created","issue":{"url":"https://api.github.com/repos/encode/django-rest-framework/issues/5345","repository_url":"https://api.github.com/repos/encode/django-rest-framework","labels_url":"https://api.github.com/repos/encode/django-rest-framework/issues/5345/labels{/name}","comments_url":"https://api.github.com/repos/encode/django-rest-framework/issues/5345/comments","events_url":"https://api.github.com/repos/encode/django-rest-framework/issues/5345/events","html_url":"https://github.com/encode/django-rest-framework/issues/5345","id":251644125,"node_id":"MDU6SXNzdWUyNTE2NDQxMjU=","number":5345,"title":"`initial_data` not as expected with many=True","user":{"login":"daggaz","id":889423,"node_id":"MDQ6VXNlcjg4OTQyMw==","avatar_url":"https://avatars0.githubusercontent.com/u/889423?v=4","gravatar_id":"","url":"https://api.github.com/users/daggaz","html_url":"https://github.com/daggaz","followers_url":"https://api.github.com/users/daggaz/followers","following_url":"https://api.github.com/users/daggaz/following{/other_user}","gists_url":"https://api.github.com/users/daggaz/gists{/gist_id}","starred_url":"https://api.github.com/users/daggaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daggaz/subscriptions","organizations_url":"https://api.github.com/users/daggaz/orgs","repos_url":"https://api.github.com/users/daggaz/repos","events_url":"https://api.github.com/users/daggaz/events{/privacy}","received_events_url":"https://api.github.com/users/daggaz/received_events","type":"User","site_admin":false},"labels":[{"id":108601,"node_id":"MDU6TGFiZWwxMDg2MDE=","url":"https://api.github.com/repos/encode/django-rest-framework/labels/Bug","name":"Bug","color":"e10c02","default":false},{"id":730098405,"node_id":"MDU6TGFiZWw3MzAwOTg0MDU=","url":"https://api.github.com/repos/encode/django-rest-framework/labels/help%20wanted","name":"help wanted","color":"fc7c2d","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2017-08-21T12:28:10Z","updated_at":"2018-09-25T06:42:37Z","closed_at":"2017-10-17T07:00:50Z","author_association":"CONTRIBUTOR","body":"## Checklist\r\n\r\n- [X] I have verified that that issue exists against the `master` branch of Django REST framework.\r\n- [X] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.\r\n- [X] This is not a usage question. (Those should be directed to the [discussion group](https://groups.google.com/forum/#!forum/django-rest-framework) instead.)\r\n- [X] This cannot be dealt with as a third party library. (We prefer new functionality to be [in the form of third party libraries](http://www.django-rest-framework.org/topics/third-party-resources/#about-third-party-packages) where possible.)\r\n- [X] I have reduced the issue to the simplest possible case.\r\n- [ ] I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)\r\n\r\n## Steps to reproduce\r\n\r\nCreate a test serializer that uses `initial_data`:\r\n```\r\nclass TestSerializer(serializers.Serializer):\r\n    number = serializers.IntegerField()\r\n    def validate(self, attrs):\r\n        print self.initial_data\r\n        return attrs\r\n```\r\n\r\nUse it:\r\n```\r\n>>> serializer = TestSerializer(data={'number': 1})\r\n>>> serializer.is_valid()\r\n{'number': 1}\r\n```\r\n\r\n`initial_data` is a `dict` as expected\r\n\r\nUse it with `many` = `True`:\r\n```\r\n>>> list_serializer = TestSerializer(data=[{'number': 1}, {'number': 1}], many=True)\r\n>>> list_serializer.is_valid()\r\n[{'number': 1}, {'number': 2}]\r\n[{'number': 1}, {'number': 2}]\r\n```\r\n`initial_data` is a `list`, even though as far as the `TestSerializer` class is concerned, it operates on individual objects.\r\n\r\n## Expected behavior\r\n\r\nThe `ListSerializer` should update the `initial_data` of it's child serializer as it is iterating. The expected output would be:\r\n```\r\n>>> list_serializer = TestSerializer(data=[{'number': 1}, {'number': 1}], many=True)\r\n>>> list_serializer.is_valid()\r\n{'number': 1}\r\n{'number': 2}\r\n```\r\n\r\n## Actual behavior\r\n\r\nBoth times the `TestSerializer` class is used it gets `initial_data` as a `list`. Therefore the class needs to know that it was called from a `ListSerializer` context to operate. This is surprising."},"comment":{"url":"https://api.github.com/repos/encode/django-rest-framework/issues/comments/424225324","html_url":"https://github.com/encode/django-rest-framework/issues/5345#issuecomment-424225324","issue_url":"https://api.github.com/repos/encode/django-rest-framework/issues/5345","id":424225324,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNDIyNTMyNA==","user":{"login":"carltongibson","id":64686,"node_id":"MDQ6VXNlcjY0Njg2","avatar_url":"https://avatars1.githubusercontent.com/u/64686?v=4","gravatar_id":"","url":"https://api.github.com/users/carltongibson","html_url":"https://github.com/carltongibson","followers_url":"https://api.github.com/users/carltongibson/followers","following_url":"https://api.github.com/users/carltongibson/following{/other_user}","gists_url":"https://api.github.com/users/carltongibson/gists{/gist_id}","starred_url":"https://api.github.com/users/carltongibson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carltongibson/subscriptions","organizations_url":"https://api.github.com/users/carltongibson/orgs","repos_url":"https://api.github.com/users/carltongibson/repos","events_url":"https://api.github.com/users/carltongibson/events{/privacy}","received_events_url":"https://api.github.com/users/carltongibson/received_events","type":"User","site_admin":false},"created_at":"2018-09-25T06:42:37Z","updated_at":"2018-09-25T06:42:37Z","author_association":"COLLABORATOR","body":"Hi @thomas-riccardi. I don't think anything has changed here. It's not at all clear that the extra complexity merits the use-case **for the core framework**. You are welcome to create you own `ListSerializer` class to provide this behaviour. If it looks good you can always open a PR to see if it'd be worth including, but likely we'd advise putting it in a third-party package. "}}
{"actor":{"display_login":"carltongibson"}}