- Notifications
You must be signed in to change notification settings - Fork302
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I want to use Traceback (mostrecentcalllast):File"...\api\.venv\lib\site-packages\asgiref\sync.py",line534,inthread_handlerraiseexc_info[1]File"...\api\.venv\lib\site-packages\django\core\handlers\exception.py",line42,ininnerresponse=awaitget_response(request)File"...\api\.venv\lib\site-packages\django\core\handlers\base.py",line284,in_get_response_asyncresponse=awaitsync_to_async(File"...\api\.venv\lib\site-packages\asgiref\sync.py",line479,in__call__ret:_R=awaitloop.run_in_executor(File"...\api\.venv\lib\site-packages\asgiref\current_thread_executor.py",line40,inrunresult=self.fn(*self.args,**self.kwargs)File"...\api\.venv\lib\site-packages\asgiref\sync.py",line538,inthread_handlerreturnfunc(*args,**kwargs)File"...\api\.venv\lib\site-packages\django\template\response.py",line114,inrenderself.content=self.rendered_contentFile"...\api\.venv\lib\site-packages\rest_framework\response.py",line70,inrendered_contentret=renderer.render(self.data,accepted_media_type,context)File"...\api\.venv\lib\site-packages\rest_framework_json_api\renderers.py",line568,inrenderself.extract_included(File"...\api\.venv\lib\site-packages\rest_framework_json_api\renderers.py",line338,inextract_includedrelation_queryset=list(relation_instance)TypeError:'NoneType'objectisnotiterable I suppose this is because the field is not intended to load the data and therefore raises an error when the data to include is |
BetaWas this translation helpful?Give feedback.
All reactions
If you use hyperlinked related fields, if you have a resource in the included array, you do not know where it would be linked to. Therefore, as I see it, it is against the spec to allow this. Seehere where it talks about full-linkage which needs to be clear by the compound document. Anyhow, I am not so sure about the use case anyway.
My suggestion is to either have all relationships as hyperlinks or use included serializers, but not both together.
Replies: 2 comments 1 reply
-
If you use hyperlinked related fields, if you have a resource in the included array, you do not know where it would be linked to. Therefore, as I see it, it is against the spec to allow this. Seehere where it talks about full-linkage which needs to be clear by the compound document. Anyhow, I am not so sure about the use case anyway. My suggestion is to either have all relationships as hyperlinks or use included serializers, but not both together. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
This is what I meant: // No ?included=images{"data":{ ...,"relationships":{"images":{"links":{"self":"URL","related":"URL",}}}}}// With ?included=images{"data":{ ...,"relationships":{"images":{"meta":{"count":1},"data":[{"type":"image","id":"500c5ecf-8d83-4333-8f0f-207941aaa552"}],"links":{"self":"URL","related":"URL",}}}},"included":[{"type":"image","id":"500c5ecf-8d83-4333-8f0f-207941aaa552","attributes":{ ...}, ...}]} This way, the user can select what to load and prevent from sending a big body with things the user won't use. In my app I have big relationships (1k resources in many-to-many) and responses take too much time to get delivered. |
BetaWas this translation helpful?Give feedback.
All reactions
-
OK I see. You can do this somehow with a custom ResourceRelatedField and custom JSONRenderer. However, I do not think that is the intended use case for compound documents, that when using include query parameter the JSON:API structure suddenly changes. If you have issues with too large bodies, I rather recommend you use sparse field sets as perspec where you can define what fields you need returned. This is supported by DJA out of the box as long as you use rest_framework_json_api.serializers.ModelSerializer for your serializers. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1