Add check for serializers.HiddenField on fields_for_serializer function (#1419)

* Add check for `serializers.HiddenField` on fields_for_serializer function

* Add pre-commit changes
This commit is contained in:
Sezgin ACER 2023-06-06 09:20:32 +03:00 committed by GitHub
parent 520ddeabf6
commit 8934393909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -39,6 +39,9 @@ def fields_for_serializer(
field.read_only
and is_input
and lookup_field != name, # don't show read_only fields in Input
isinstance(
field, serializers.HiddenField
), # don't show hidden fields in Input
]
)

View File

@ -164,6 +164,21 @@ def test_read_only_fields():
), "'cool_name' is read_only field and shouldn't be on arguments"
def test_hidden_fields():
class SerializerWithHiddenField(serializers.Serializer):
cool_name = serializers.CharField()
user = serializers.HiddenField(default=serializers.CurrentUserDefault())
class MyMutation(SerializerMutation):
class Meta:
serializer_class = SerializerWithHiddenField
assert "cool_name" in MyMutation.Input._meta.fields
assert (
"user" not in MyMutation.Input._meta.fields
), "'user' is hidden field and shouldn't be on arguments"
def test_nested_model():
class MyFakeModelGrapheneType(DjangoObjectType):
class Meta: