Closed
Description
Checklist
- I have verified that that issue exists against the
master
branch of Django REST framework. - I have searched for similar issues in both open and closed tickets and cannot find a duplicate. (Fix serializer multiple inheritance bug #6980 and Inheriting multiple Serializers gives unexpected order of overloading of fields #5798 are related.)
- This is not a usage question. (Those should be directed to the discussion group instead.)
- This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
- I have reduced the issue to the simplest possible case.
- I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
Steps to reproduce
from rest_framework import serializers
# dummy fields for demonstration
class AllProductsField(serializers.Field): pass
class SupportedProductsField(serializers.Field): pass
class CommonSerializer(serializers.Serializer):
product = AllProductsField()
class CustomerAccess(CommonSerializer):
def validate_product(self, value):
return do_something(value)
class TicketSerializer(CommonSerializer):
product = SupportedProductsField()
class CustomerTicketSerializer(CustomerAccess, TicketSerializer):
pass
print('[' + ' > '.join(x.__name__ for x in CustomerTicketSerializer.mro()[:4]) + ']')
print(str(CustomerTicketSerializer()))
Expected behavior
[CustomerTicketSerializer > CustomerAccess > TicketSerializer > CommonSerializer]
CustomerTicketSerializer():
product = SupportedProductsField()
Actual behavior
[CustomerTicketSerializer > CustomerAccess > TicketSerializer > CommonSerializer]
CustomerTicketSerializer():
product = AllProductsField()
Remarks
For compatibility I think this behavior shall be kept for a while, but not respecting Python MRO may turn out to be astonishing for some users and even lead to potential security problems (e.g. choice-limiting queryset not properly overridden).
Metadata
Metadata
Assignees
Labels
No labels