Skip to content

typing-extensions 4.13.0 breaks pydantic (<2.10) and SQLAlchemy (latest) project when using custom type #560

Description

@Giuzzilla

It seems that by upgrading typing-extensions from 4.12.2 to 4.13.0, a project with a simple Pydantic model referencing a custom type breaks.

Reproducible example:

fromtypingimportLiteralfrompydanticimportBaseModel
type MyType=Literal["test1", "test2"]
classTest(BaseModel):
a: intb: MyType

Throws:

pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for MyType. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.
If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.

I'm on Pydantic 2.9.0 and Python 3.12.9

I'm not sure if this is an issue on pydantic side and whether it should be fixed there, just pretty sure that it starts to break with 4.13.0

EDIT (see conversation):
Pydantic seems fixed on >=2.10

SQLAlchemy is broken on the latest available version (2.0.39) with a very similar case:

fromtypingimportLiteralfromsqlalchemy.ormimportDeclarativeBase, Mapped, mapped_column
type MyType=Literal["test1", "test2"]
classBase(DeclarativeBase):
passclassMyModel(Base):
__tablename__="my_model"id: Mapped[int] =mapped_column(primary_key=True)
my_type: Mapped[MyType]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions