Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for serializers.HiddenField on fields_for_serializer function #1419

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions graphene_django/rest_framework/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
)

Expand Down
15 changes: 15 additions & 0 deletions graphene_django/rest_framework/tests/test_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ class Meta:
), "'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:
Expand Down