-
Notifications
You must be signed in to change notification settings - Fork 297
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
Primary key optimization doesn't work (null attribtue values) with nested includes #708
Comments
An include When looking at the history between version 2.5.0 and 2.6.0 it is not obvious which commit could have broken this. I am also using this type of include in some of my projects and there I don't see the issue you are seeing. Hence some questions:
Thanks. |
Okay, I was able to get this to work after looking at the example code. If I change my I think I did find where this stopped working when using the
it is now:
Before this change was made, a ModelSerializer like the It seems like this code may be working as intended and I just need to update my serializers to use |
Actually I'm thinking there is still a bug here. Another change that was made in that commit was adding a check for the field's
That
this restores the functionality and allows nested includes to be serialized correctly when using There may be some other concerns with doing this though - I can see a scenario where a model and its child models both have fields with the same name, especially when it comes to related users (both models having a |
I have overlooked this when I looked at your example that you use a serializer instead of a ResourceRelatedField. A serializer in rest framework would actually embed the relation whereas a PrimaryKeyRelatedField which All in all I still think embedding a serializer should work as you do it for DRF compatibility although it is not the the preferred way. Marking this as a bug therefore as you also outline there are issue with related fields. We have to think about it how to implement it though. The way how primary key optimization is done currently is complicated and I would prefer to use Any contributions are welcome. |
I ran into this issue when upgrading to a newer version of
django-rest-framework-json-api
and it seems like a bug to me, unless there is now a different way that this is meant to be accomplished that I'm not seeing in the documentation. The problem is when providing aninclude
parameter for nested children of a resource (for example,?include=articles.author
), those "grandchild" objects are present in theincluded
but they have noattributes
.I was able to recreate this with a simple setup:
Models
Serializers
The view is just a simple
ModelViewSet
.The output of a query
/page/?include=articles.author
is this:The
first_name
andlast_name
fields for the included Author are present but have null values, when data exists in the database for this object. This issue seems to have been introduced indjango-rest-framework-json-api
v2.6.0, as the fields are returned correctly when using 2.5.0.The text was updated successfully, but these errors were encountered: