Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError: HyperlinkedIdentityField requires the request in the serializer context. #12

Closed
Lucianovici opened this issue Oct 15, 2014 · 5 comments

Comments

@Lucianovici
Copy link

Hi,

It looks like I don't get a warning, but I get an assertion error.

image

>>> serializer = UserSerializer(user)
>>> serializer.data
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/work/playground/python/django-angular/virtualenv/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 572, in data
    self._data = self.to_native(obj)
  File "/work/playground/python/django-angular/virtualenv/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 351, in to_native
    value = field.field_to_native(obj, field_name)
  File "/work/playground/python/django-angular/virtualenv/local/lib/python2.7/site-packages/rest_framework/relations.py", line 529, in field_to_native
    "`HyperlinkedIdentityField` requires the request in the serializer"
AssertionError: `HyperlinkedIdentityField` requires the request in the serializer context. Add `context={'request': request}` when instantiating the serializer.

@kevinastone
Copy link
Owner

Thanks for the report. Let me look into this (looks like a 2.2+ update) and figure out a fix.

@edgartaor
Copy link

I'm getting the same assertion error.

@limbera
Copy link

limbera commented Dec 6, 2014

i am getting the same assertion error just using curl and vanilla DRF - so i think the problem might be with DRF itself.

@kevinastone
Copy link
Owner

I updated the blog post to pass in a context with a fake request object.
http://blog.kevinastone.com/getting-started-with-django-rest-framework-and-angularjs.html#model-serializers

@Lucianovici
Copy link
Author

Thanks @kevinastone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants