Skip to content

Pydantic Input Types behavior is strange #4042

@c-xlenz

Description

@c-xlenz

Describe the Bug

I have a pydantic class

class UserModel(pydantic.BaseModel):
    name: str
    interests: list[str] | None = pydantic.Field(
        default_factory=list, description="The list of user interests."
    )

Now building a strawberry input type:

@strawberry.experimental.pydantic.input(
    model=UserModel,
    description="""Input type for updating a User.""",
)
class UpdateUserInput:
    name: strawberry.auto
    interests: strawberry.auto

and building the mutation:

 @strawberry.mutation
    async def update_user(
        self,
        root: Any,
        info: strawberry.types.Info,
        user_data: UpdateUserInput,
    ) :
      ....

assuming I have a user in the db that already has interests ["reading", "cooking"] and I want to update the name.
My mutation would look something like this:

mutation {
  update_user(user_data: {name: "New Name"})
...
}

Now what I see when looking at the user_data in the update_user function is:

user_data=UpdateUserInput(name='New Name', interests=[])

I would have expected to only see the set values or have the option somehow to filter out unset values... Otherwise partial updates are not possible.

System Information

  • Operating system: Debian
  • Python version: 3.13
  • Strawberry version (if applicable): strawberry-graphql==0.284.1

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions