Skip to content

Commit 36cf32b

Browse files
author
Leifur Halldor Asgeirsson
committed
Fix crash with serializers that have fields which do not exist on the model.
Change utils.extract_relationships to skip fields defined on the serializer that don't correspond to a field on the model.
1 parent a4ae22c commit 36cf32b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

rest_framework_json_api/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ def extract_relationships(fields, resource, resource_instance):
229229
continue
230230

231231
relation_type = get_related_resource_type(field)
232-
relation_instance_or_manager = getattr(resource_instance, field_name)
232+
try:
233+
relation_instance_or_manager = getattr(resource_instance, field_name)
234+
except AttributeError: # Skip fields defined on the serializer that don't correspond to a field on the model
235+
continue
233236

234237
if isinstance(field, HyperlinkedIdentityField):
235238
# special case for HyperlinkedIdentityField

0 commit comments

Comments
 (0)