graphql-python / graphql-python/graphene-pydantic

Not working list[str] field

Open
#83 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
249
Forks
47
PR merge metrics
No merged PRs in 30d

Description

I found graphene-pydantic fails converting `list[str]` field.
```python
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
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 for field field is not allowed: use default_factory
```

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.