10000 a field named "items" in InputObjectType occurs TypeError · Issue #1150 · graphql-python/graphene · GitHub
[go: up one dir, main page]

Skip to content
a field named "items" in InputObjectType occurs TypeError  #1150
Open
@jiyeonseo

Description

@jiyeonseo

I was trying to json.dumps with all inputs and some inputs had TypeError when they have a field named "items" like below.

class ConfigInput(graphene.InputObjectType):	    
    items = graphene.List(lambda: AnotherConfigInput)
    ...

when I try to json.dumps with this input, the error looks like

File "/project/venv/lib/python3.7/site-packages/playhouse/mysql_ext.py", line 36, in db_value
    return json.dumps(value)
  File "/Users/user/.pyenv/versions/3.7.4/lib/python3.7/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/Users/user/.pyenv/versions/3.7.4/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Users/user/.pyenv/versions/3.7.4/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
TypeError: attribute of type 'list' is not callable

found that setattr in InputObjectType class overrides field's attr items which conflicts with the attribute items of List.

This is naming conflict, so I just solved it like below

class ConfigInput(graphene.InputObjectType):
    _items = graphene.List(lambda: AnotherConfigInput, name='items')
    ...

wonder if there is any good fix from graphene like this issue

please let me know if you need more info or examples :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0