Skip to content

Commit 143a0cd

Browse files
author
Leifur Halldor Asgeirsson
committed
bugfix in extract_included
fix a bug that caused a 500 error when a to-one related field specified in the include parameter has a value of null
1 parent 2faeca2 commit 143a0cd

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

rest_framework_json_api/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@ def extract_included(fields, resource, resource_instance, included_resources):
413413

414414
try:
415415
included_resources.remove(field_name)
416+
new_included_resources = [key.replace('%s.' % field_name, '', 1) for key in included_resources]
416417
relation_instance_or_manager = getattr(resource_instance, field_name)
417418
serializer_data = resource.get(field_name)
418-
new_included_resources = [key.replace('%s.' % field_name, '', 1) for key in included_resources]
419419
except ValueError:
420420
# Skip fields not in requested included resources
421421
continue
@@ -427,6 +427,8 @@ def extract_included(fields, resource, resource_instance, included_resources):
427427

428428
if isinstance(field, RelatedField):
429429
serializer_class = included_serializers.get(field_name)
430+
if relation_instance_or_manager is None:
431+
continue
430432
field = serializer_class(relation_instance_or_manager, context=context)
431433
serializer_data = field.data
432434

0 commit comments

Comments
 (0)