Docs about default value for dotted source, additional tests by rpkilby · Pull Request #5489 · encode/django-rest-framework (original) (raw)

WIP changes to docs, and additional tests for behavior of source w/ dotted notation.

Closes #5488.

Waiting for a nested ModelSerializer example from @xordoquy.

Also, is the current exception sufficient, or do we need to mention the necessity of a default value?
eg, this serializer:

class ColleagueUserSerializer(BaseModelSerializer): city = serializers.IntegerField(source='profile.contact.address.city')

generates this exception:

AttributeError: Got AttributeError when attempting to get a value for field `city` on serializer `ColleagueUserSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `User` instance.
Original exception text was: 'NoneType' object has no attribute 'address'.