Skip to content

Commit ba5f46b

Browse files
committed
Fix the inclusion of relations
When getting a list and including data from the models in the list, only the related data of the first model in the list was included
1 parent 279df07 commit ba5f46b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

rest_framework_json_api/utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,13 @@ def extract_included(fields, resource, resource_instance, included_resources):
413413
if not isinstance(field, (RelatedField, ManyRelatedField, BaseSerializer)):
414414
continue
415415

416-
try:
417-
included_resources.remove(field_name)
418-
new_included_resources = [key.replace('%s.' % field_name, '', 1) for key in included_resources]
419-
relation_instance_or_manager = getattr(resource_instance, field_name)
420-
serializer_data = resource.get(field_name)
421-
except ValueError:
416+
if field_name not in included_resources:
422417
# Skip fields not in requested included resources
423418
continue
419+
420+
new_included_resources = [key.replace('%s.' % field_name, '', 1) for key in included_resources]
421+
relation_instance_or_manager = getattr(resource_instance, field_name)
422+
serializer_data = resource.get(field_name)
424423

425424
if isinstance(field, ManyRelatedField):
426425
serializer_class = included_serializers.get(field_name)

0 commit comments

Comments
 (0)