Description
This was introduced by #5518, and while the solutions there work on normal fields, RelatedField behaves differently:
django-rest-framework/rest_framework/fields.py
Lines 440 to 442 in da535d3
vs
An example of the problem can be reproduced with https://gist.github.com/gcbirzan/a968facbaf0969f4a9616942de7022dc
A Model1
instance with None
for model2
will produce an exception.
I believe that the correct behaviour is for RelatedField.get_attribute
to call super.
As a side note, this is very hacky to work around, you'll need to copy paste the code from RelatedField.get_attribute
in your class, then call the Field.get_attribute
, since obviously super won't work.
If there's some agreement that this is the solution, I can fix it, but I'm not 100% sure (given the reaction on the original ticket) if this is considered a bug.