Skip to content

Pydantic Union with SkipJsonSchema breaks schema generation #3992

@mskrip

Description

@mskrip

Describe the Bug

When using SkipJsonSchema annotation in a type union, the schema generation fails with Type str cannot be used in a GraphQL Union

Minimal replicating example:

import strawberry
from pydantic import BaseModel
from pydantic.json_schema import SkipJsonSchema


class ModelA(BaseModel):
    field_a: str | SkipJsonSchema[None] = None


@strawberry.experimental.pydantic.type(
    model=ModelA,
    all_fields=True,
)
class TypeA:
    pass


@strawberry.type
class Query:
    @strawberry.field
    def example(self) -> TypeA:
        return TypeA()


schema = strawberry.Schema(query=Query)
print(schema.as_str())

This pattern is useful for denoting the field as not required but without explicit type: none in JSON schema generated from Pydantic

System Information

  • Operating system: Ubuntu
  • Python version: 3.13
  • Strawberry version (if applicable): 0.282.0

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