{"action":"closed","issue":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2560","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2560/labels{/name}","comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2560/comments","events_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2560/events","html_url":"https://github.com/tomchristie/django-rest-framework/issues/2560","id":57783057,"number":2560,"title":"Attribute error when using serializer data in post_create","user":{"login":"timlacroix","id":4998695,"avatar_url":"https://avatars.githubusercontent.com/u/4998695?v=3","gravatar_id":"","url":"https://api.github.com/users/timlacroix","html_url":"https://github.com/timlacroix","followers_url":"https://api.github.com/users/timlacroix/followers","following_url":"https://api.github.com/users/timlacroix/following{/other_user}","gists_url":"https://api.github.com/users/timlacroix/gists{/gist_id}","starred_url":"https://api.github.com/users/timlacroix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timlacroix/subscriptions","organizations_url":"https://api.github.com/users/timlacroix/orgs","repos_url":"https://api.github.com/users/timlacroix/repos","events_url":"https://api.github.com/users/timlacroix/events{/privacy}","received_events_url":"https://api.github.com/users/timlacroix/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-16T09:45:25Z","updated_at":"2015-02-17T20:11:26Z","closed_at":"2015-02-17T20:11:26Z","body":"Hey,\r\n\r\nI have a HyperLinkedModelSerializer. To create it I need to check whether some field in serializer.data matches the request user.\r\nI do this in post_create in my list view (generics.ListCreateAPIView).\r\n\r\nHere is my exact perform_create :\r\n```python\r\ndef perform_create(self, serializer):\r\n        if not (self.request.user.username == serializer.data['username']):\r\n            raise PermissionDenied()\r\n        serializer.save()\r\n```\r\nAnd the traceback : \r\n```\r\nTraceback (most recent call last):\r\n  File \"python2.7/site-packages/django/core/handlers/base.py\", line 111, in get_response\r\n    response = wrapped_callback(request, *callback_args, **callback_kwargs)\r\n  File \"python2.7/site-packages/django/views/decorators/csrf.py\", line 57, in wrapped_view\r\n    return view_func(*args, **kwargs)\r\n  File \"python2.7/site-packages/django/views/generic/base.py\", line 69, in view\r\n    return self.dispatch(request, *args, **kwargs)\r\n  File \"python2.7/site-packages/rest_framework/views.py\", line 407, in dispatch\r\n    response = self.handle_exception(exc)\r\n  File \"python2.7/site-packages/rest_framework/views.py\", line 404, in dispatch\r\n    response = handler(request, *args, **kwargs)\r\n  File \"python2.7/site-packages/rest_framework/generics.py\", line 314, in post\r\n    return self.create(request, *args, **kwargs)\r\n  File \"python2.7/site-packages/rest_framework/mixins.py\", line 21, in create\r\n    self.perform_create(serializer)\r\n  File \"backend/api_views.py\", line 50, in perform_create\r\n    if not (self.request.user.username == serializer.data['username']):\r\n  File \"python2.7/site-packages/rest_framework/serializers.py\", line 463, in data\r\n    ret = super(Serializer, self).data\r\n  File \"python2.7/site-packages/rest_framework/serializers.py\", line 214, in data\r\n    self._data = self.to_representation(self.validated_data)\r\n  File \"python2.7/site-packages/rest_framework/serializers.py\", line 432, in to_representation\r\n    ret[field.field_name] = field.to_representation(attribute)\r\n  File \"python2.7/site-packages/rest_framework/relations.py\", line 257, in to_representation\r\n    return self.get_url(value, self.view_name, request, format)\r\n  File \"python2.7/site-packages/rest_framework/relations.py\", line 200, in get_url\r\n    if obj.pk is None:\r\nAttributeError: 'OrderedDict' object has no attribute 'pk'\r\n```\r\nThe error seems to come from trying to create the url field when the object hasn't been created yet ... But I'm a total n00b with django-rest-framework so ... \r\n\r\nThanks for your help,\r\n\r\nTimothée Lacroix"}}