Closed as not planned
Description
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
Labels
No labels