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

Not working list[str] field #83

Open
conao3 opened this issue Jan 9, 2023 · 0 comments
Open

Not working list[str] field #83

conao3 opened this issue Jan 9, 2023 · 0 comments

Comments

@conao3
Copy link
Contributor

conao3 commented Jan 9, 2023

I found graphene-pydantic fails converting list[str] field.

import graphene
import pydantic

import graphene_pydantic


class Model(pydantic.BaseModel):
    field: list[str] = []


class GrapheneModel(graphene_pydantic.PydanticObjectType):
    class Meta:
        model = Model


class Query(graphene.ObjectType):
    model = graphene.Field(GrapheneModel)
    hello = graphene.String()

    @staticmethod
    def resolve_model(parent, info):
        return Model()


schema = graphene.Schema(query=Query)
print(schema)
print(schema.execute('{model {field}}'))

saved as tmp.conao3/04_list.sample.py and run like this

$ poetry run python tmp.conao3/04_list.sample.py

then, you see error.

Traceback (most recent call last):
  File "/home/conao/dev/forks/graphene-pydantic/tmp.conao3/04_list.sample.py", line 11, in <module>
    class GrapheneModel(graphene_pydantic.PydanticObjectType):
  File "/home/conao/dev/forks/graphene-pydantic/.venv/lib/python3.10/site-packages/graphene/types/objecttype.py", line 45, in __new__
    dataclass = make_dataclass(name_, fields, bases=())
  File "/usr/lib/python3.10/dataclasses.py", line 1401, in make_dataclass
    return dataclass(cls, init=init, repr=repr, eq=eq, order=order,
  File "/usr/lib/python3.10/dataclasses.py", line 1185, in dataclass
    return wrap(cls)
  File "/usr/lib/python3.10/dataclasses.py", line 1176, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
  File "/usr/lib/python3.10/dataclasses.py", line 956, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
  File "/usr/lib/python3.10/dataclasses.py", line 813, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'list'> for field field is not allowed: use default_factory

I use now main(2fd67a8) and I use Python3.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant