Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Not working list[str] field

Open
#83 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
api

Research direction

Start by running tmp.conao3/04_list.sample.py with poetry run python tmp.conao3/04_list.sample.py to reproduce the failure while defining GrapheneModel. Trace how the list[str] field is converted and ensure the schema can be created and {model {field}} executes without the mutable-default error.

Written by the indexing model from the issue text.

Description

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

Dominant language
Python
Stars
249
Forks
47
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from graphql-python/graphene-pydantic

All issues in graphql-python/graphene-pydantic

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.