Skip to content

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

@Giuzzilla

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:

from typing import Literal

from pydantic import BaseModel

type MyType = Literal["test1", "test2"]

class Test(BaseModel):
    a: int
    b: 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:

from typing import Literal

from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

type MyType = Literal["test1", "test2"]


class Base(DeclarativeBase):
    pass


class MyModel(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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy