Skip to content

Commit 4e95bb4

Browse files
author
Leifur Halldor Asgeirsson
committed
get related instance or manager before getting relation type
in case this is a custom field that doesn't exist on the model
1 parent 36cf32b commit 4e95bb4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

rest_framework_json_api/utils.py

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

231-
relation_type = get_related_resource_type(field)
232231
try:
233232
relation_instance_or_manager = getattr(resource_instance, field_name)
234233
except AttributeError: # Skip fields defined on the serializer that don't correspond to a field on the model
235234
continue
236235

236+
relation_type = get_related_resource_type(field)
237+
237238
if isinstance(field, HyperlinkedIdentityField):
238239
# special case for HyperlinkedIdentityField
239240
relation_data = list()

0 commit comments

Comments
 (0)