Skip to content

Commit dc64c20

Browse files
committed
Fixed issue with empty "ToOne" relationship being returned as empty lists.
1 parent 7979db0 commit dc64c20

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

rest_framework_json_api/views.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
from django.db.models.manager import BaseManager
33
from rest_framework import generics
44
from rest_framework.response import Response
5-
from rest_framework.renderers import JSONRenderer
5+
from rest_framework.exceptions import NotFound
6+
67
from rest_framework_json_api.serializers import ResourceIdentifierObjectSerializer
78
from rest_framework_json_api.utils import format_relation_name, get_resource_type_from_instance
8-
from rest_framework.exceptions import NotFound
99

1010

1111
class RelationshipView(generics.GenericAPIView):
1212
serializer_class = ResourceIdentifierObjectSerializer
13-
renderer_classes = (JSONRenderer, )
1413

1514
def get(self, request, *args, **kwargs):
1615
related_instance = self.get_related_instance()
@@ -40,7 +39,7 @@ def get_related_instance(self):
4039
raise NotFound
4140

4241
def _instantiate_serializer(self, instance):
43-
if isinstance(instance, Model):
42+
if isinstance(instance, Model) or instance is None:
4443
return self.get_serializer(instance=instance)
4544
else:
4645
if isinstance(instance, (QuerySet, BaseManager)):

0 commit comments

Comments
 (0)