-
Notifications
You must be signed in to change notification settings - Fork 301
Nested serializers only work with Django Model objects #249
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
Comments
DJA uses a model's
in your |
Thanks for the quick answer. I did try to define that This is the stack trace I'm getting: 2016-06-02 18:20:34,464 ERROR django.request Internal Server Error: /users/
Traceback (most recent call last):
File "/home/vagrant/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 164, in get_response
response = response.render()
File "/home/vagrant/env/local/lib/python2.7/site-packages/django/template/response.py", line 158, in render
self.content = self.rendered_content
File "/home/vagrant/env/local/lib/python2.7/site-packages/rest_framework/response.py", line 71, in rendered_content
ret = renderer.render(self.data, media_type, context)
File "/home/vagrant/env/local/lib/python2.7/site-packages/rest_framework_json_api/renderers.py", line 463, in render
json_api_data = self.build_json_resource_obj(fields, serializer_data, resource_instance, resource_name)
File "/home/vagrant/env/local/lib/python2.7/site-packages/rest_framework_json_api/renderers.py", line 369, in build_json_resource_obj
relationships = JSONRenderer.extract_relationships(fields, resource, resource_instance)
File "/home/vagrant/env/local/lib/python2.7/site-packages/rest_framework_json_api/renderers.py", line 100, in extract_relationships
relation_type = utils.get_related_resource_type(field)
File "/home/vagrant/env/local/lib/python2.7/site-packages/rest_framework_json_api/utils.py", line 181, in get_related_resource_type
parent_model = parent_serializer.parent.Meta.model
AttributeError: 'NoneType' object has no attribute 'Meta'
[02/Jun/2016 18:20:34] "GET /users/ HTTP/1.0" 500 146083
The |
Just came across the same issue. I will fix this in the coming hours. Pull request incoming. |
Ok I made an initial fix, but I had to change more than I expected. This should work now:
All current tests are passed. But I didn't write any new tests, because modelles Serializer's aren't really tested right now. What should we do next? |
@adaptivdesign Thanks for such a prompt fix, I confirm that it no longer crashes.
Anyway, many thanks for help and quick fixing! You guys rock 👍 This is my output currently: {
"data": {
"type": "users",
"id": "tmp-953157",
"attributes": {
"name": "Bob"
},
"relationships": {
"posts": {
"data": [
{
"type": "post",
"id": "tmp-545551"
},
{
"type": "post",
"id": "tmp-612679"
}
]
}
}
}
} UPDATE 2: I have created PR #250 that implements this new option to specify resources to be included by default. |
@adaptivdesign RE
We did add |
Okay, do you want me to do these? I'll have to find some spare time for it. Regarding the tests and docs, besides mentioning the JSONAPIMeta changes, what about the changes to the serialization behaviour. Right now the example resources "Blog, Entry, etc" are all models, in order to test regular serializers, we would need to add (or possibly rewrite) quite some tests. |
I'd be in favor of moving jsonapi options to the |
Closed by #265 |
While DRF works perfectly fine with simple non-model instances, DJA crashes and can't be made to work correctly.
For example, this code works fine with DRF:
However, after uncommenting the line that specifies the JSON API renderer class to be used, the view crashes with:
'NoneType' object has no attribute 'Meta'
If DJA does not support Model-less references, it could at least be clearly stated in the documentation, mentioning also some workarounds if such exist. Though, I have not found any way to make this working yet.
The text was updated successfully, but these errors were encountered: