Skip to content

Commit fc69e1e

Browse files
committed
Merge pull request #103 from ZEROFAIL/develop
Fix crash with serializers that have fields which do not exist on the…
2 parents 578e87d + 4e95bb4 commit fc69e1e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rest_framework_json_api/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,12 @@ def extract_relationships(fields, resource, resource_instance):
228228
if not isinstance(field, (RelatedField, ManyRelatedField, BaseSerializer)):
229229
continue
230230

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

234238
if isinstance(field, HyperlinkedIdentityField):
235239
# special case for HyperlinkedIdentityField

0 commit comments

Comments
 (0)