@@ -19,6 +19,8 @@ class ResourceRelatedField(PrimaryKeyRelatedField):
1919 'does_not_exist' : _ ('Invalid pk "{pk_value}" - object does not exist.' ),
2020 'incorrect_type' : _ ('Incorrect type. Expected resource identifier object, received {data_type}.' ),
2121 'incorrect_relation_type' : _ ('Incorrect relation type. Expected {relation_type}, received {received_type}.' ),
22+ 'missing_type' : _ ('Invalid resource identifier object: missing \' type\' attribute' ),
23+ 'missing_id' : _ ('Invalid resource identifier object: missing \' id\' attribute' ),
2224 'no_match' : _ ('Invalid hyperlink - No URL match.' ),
2325 }
2426
@@ -117,8 +119,16 @@ def to_internal_value(self, data):
117119 if not isinstance (data , dict ):
118120 self .fail ('incorrect_type' , data_type = type (data ).__name__ )
119121 expected_relation_type = get_resource_type_from_queryset (self .queryset )
122+
123+ if 'type' not in data :
124+ self .fail ('missing_type' )
125+
126+ if 'id' not in data :
127+ self .fail ('missing_id' )
128+
120129 if data ['type' ] != expected_relation_type :
121130 self .conflict ('incorrect_relation_type' , relation_type = expected_relation_type , received_type = data ['type' ])
131+
122132 return super (ResourceRelatedField , self ).to_internal_value (data ['id' ])
123133
124134 def to_representation (self , value ):
0 commit comments