Skip to content

Commit 195814a

Browse files
sezginacersuperlevure
authored andcommitted
Add check for serializers.HiddenField on fields_for_serializer function (graphql-python#1419)
* Add check for `serializers.HiddenField` on fields_for_serializer function * Add pre-commit changes
1 parent 51b8179 commit 195814a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

graphene_django/rest_framework/mutation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def fields_for_serializer(
3939
field.read_only
4040
and is_input
4141
and lookup_field != name, # don't show read_only fields in Input
42+
isinstance(
43+
field, serializers.HiddenField
44+
), # don't show hidden fields in Input
4245
]
4346
)
4447

graphene_django/rest_framework/tests/test_mutation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,21 @@ class Meta:
164164
), "'cool_name' is read_only field and shouldn't be on arguments"
165165

166166

167+
def test_hidden_fields():
168+
class SerializerWithHiddenField(serializers.Serializer):
169+
cool_name = serializers.CharField()
170+
user = serializers.HiddenField(default=serializers.CurrentUserDefault())
171+
172+
class MyMutation(SerializerMutation):
173+
class Meta:
174+
serializer_class = SerializerWithHiddenField
175+
176+
assert "cool_name" in MyMutation.Input._meta.fields
177+
assert (
178+
"user" not in MyMutation.Input._meta.fields
179+
), "'user' is hidden field and shouldn't be on arguments"
180+
181+
167182
def test_nested_model():
168183
class MyFakeModelGrapheneType(DjangoObjectType):
169184
class Meta:

0 commit comments

Comments
 (0)