From d13cd397b6ce1ab0eeed0effb43904eb54869819 Mon Sep 17 00:00:00 2001 From: Ignacio Gonzalez <8524584+nchz@users.noreply.github.com> Date: Sun, 19 Mar 2023 15:23:11 -0300 Subject: [PATCH] disallow same field name in both `exclude` and `include`. --- rest_framework/serializers.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index be925d35f..7d12e188c 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -1130,6 +1130,13 @@ class ModelSerializer(Serializer): ) ) + assert set(exclude or []).isdisjoint(include or []), ( + "Cannot set the same field name in both 'exclude' and 'include' options " + "on serializer {serializer_class}.".format( + serializer_class=self.__class__.__name__ + ) + ) + # TODO Review the message of this assertion. assert not (fields is None and exclude is None and include is None), ( "Creating a ModelSerializer without either the 'fields', 'exclude' "