{"id":15612410,"url":"https://github.com/kylefox/django-rest-bug","last_synced_at":"2025-10-03T18:05:03.797Z","repository":{"id":36262704,"uuid":"40567139","full_name":"kylefox/django-rest-bug","owner":"kylefox","description":null,"archived":false,"fork":false,"pushed_at":"2015-08-11T22:15:54.000Z","size":120,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-04T11:36:14.492Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kylefox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-11T21:56:36.000Z","updated_at":"2015-08-11T21:56:50.000Z","dependencies_parsed_at":"2022-09-04T14:40:47.981Z","dependency_job_id":null,"html_url":"https://github.com/kylefox/django-rest-bug","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kylefox/django-rest-bug","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kylefox%2Fdjango-rest-bug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kylefox%2Fdjango-rest-bug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kylefox%2Fdjango-rest-bug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kylefox%2Fdjango-rest-bug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kylefox","download_url":"https://codeload.github.com/kylefox/django-rest-bug/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kylefox%2Fdjango-rest-bug/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259727133,"owners_count":22902181,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T06:42:40.672Z","updated_at":"2025-10-03T18:05:03.701Z","avatar_url":"https://github.com/kylefox.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Demonstrates a bug where merely accessing `serializer.data` causes its internal value to change.\n\nIn short, when POSTing to create we expect the full serialized version of the object to be returned in `response.data`. However, if `serialize.data` is used inside the viewset's `perform_create()` method, it causes `response.data` to be whatever the initial POST data was.\n\nEven if `serializer.data` is not \"safe\", I think it's wrong for the internal data to change simply by accessing a property. Typically you don't expect property access to have side effects.\n\n## Setup\n\n```\ngit clone git@github.com:kylefox/django-rest-bug.git\ncd django-rest-bug\npip install -q -r requirements.txt\npython manage.py test\n```\n\n## Relevant Code Snippets\n\n```python\n# models.py\nclass Album(models.Model):\n\n    title = models.CharField(max_length=250)\n    artist = models.CharField(max_length=250)\n\n\n# serializers.py  \nclass AlbumSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = Album\n        fields = ('id', 'title', 'artist')\n\n\n# views.py\nclass AlbumViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet):\n\n    serializer_class = AlbumSerializer\n    queryset = Album.objects.all()\n\n    def perform_create(self, serializer):\n\n        # If `serializer.data` is present, it will screw up `response.data`\n        # (Comment line below to watch tests pass)\n        serializer.data\n\n        serializer.save()\n\n\n# tests.py\nclass CreateAlbumTestCase(APITestCase):\n\n    def test_create_album(self):\n        post_data = {'title': 'The Wall', 'artist': 'Pink Floyd'}\n        response = self.client.post(reverse('album-list'), post_data)\n\n        # THIS ASSERTION FAILS WHEN `serializer.data` IS CALLED IN `perform_create()`\n        assert 'id' in response.data, \"Key `id` isn't in `response.data`\"\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkylefox%2Fdjango-rest-bug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkylefox%2Fdjango-rest-bug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkylefox%2Fdjango-rest-bug/lists"}