Fix dotted source ordering by carltongibson · Pull Request #5533 · encode/django-rest-framework (original) (raw)

Replaces #5525.

Comment from original PR:

I ran into an issue the other day where a serializer referring to a field in a related object didn't provide the correct field name for the ordering filter backend.

Updating the get_default_valid_fields method so that for dotted sources the . for __ fixes my use case.

I just added a test to check the non-dotted source didn't raise an AttributeError calling replace on None. (It doesn't: Serializer.fields provides a sensible source even when None on the field.)