diff --git a/graphene/core/classtypes/objecttype.py b/graphene/core/classtypes/objecttype.py index 2bcb5e68..c5559fab 100644 --- a/graphene/core/classtypes/objecttype.py +++ b/graphene/core/classtypes/objecttype.py @@ -80,7 +80,7 @@ class ObjectType(six.with_metaclass(ObjectTypeMeta, FieldsClassType)): if kwargs: for prop in list(kwargs): try: - if isinstance(getattr(self.__class__, prop), property): + if isinstance(getattr(self.__class__, prop), property) or prop.startswith('_'): setattr(self, prop, kwargs.pop(prop)) except AttributeError: pass diff --git a/graphene/core/classtypes/tests/test_objecttype.py b/graphene/core/classtypes/tests/test_objecttype.py index c554dbbf..609975f2 100644 --- a/graphene/core/classtypes/tests/test_objecttype.py +++ b/graphene/core/classtypes/tests/test_objecttype.py @@ -55,6 +55,17 @@ def test_object_type_set_properties(): assert h.write_prop == 'custom' +def test_object_type_set_private_attributes(): + class Human(ObjectType): + _private_state = None + + h = Human(_private_state='custom') + assert h._private_state == 'custom' + + with raises(TypeError): + Human(_other_private_state='My name') + + def test_object_type_container_invalid_kwarg(): class Human(ObjectType): name = String()