-
-
Notifications
You must be signed in to change notification settings - Fork 117
typing-extensions 4.13.0 breaks pydantic (<2.10) and SQLAlchemy (latest) project when using custom type #560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Seems to be fine with the combination of Pydantic |
This is interesting, as typing-extensions had no |
But FWIW, I can reproduce the problem using Python 3.12.7 and pydantic 2.10.6 (working)/2.9.2 (not working). |
Just to add to the strangeness of the issue, upgrading pydantic does fix the error on the example I made above, but let's suppose I use that type also in a
I can give a full example later (I'm just finding this out because I had indeed a Literal type in my real project used both by a declarative model on SQLAlchemy and on a Pydantic model) |
Here is a reproducible example of a simple SQLAlchemy (latest, 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]
Again, no issues with typing-extensions |
The error going-away bisects to pydantic/pydantic#10713 (released with v2.10.0). The history is linked from there. Seems that this was an issue prompted by #477, caught by our CI (#493), and fixed in pydantic before 4.13.0 was released. |
PS: This gives a SQLAlchemy's deprecation warning about type_annotation_map, but even if you add it to the type_annotation_map you still get the same error on |
The error originates from the existence of A fix, without upgrading pydantic, is to not use the from typing import Literal
from typing_extensions import TypeAliasType
from pydantic import BaseModel
MyType = TypeAliasType("MyType", Literal["test1", "test2"])
class Test(BaseModel):
a: int
b: MyType |
Yes, either removing However, SQLAlchemy seems to have a similar issue and has no fixed version for what I understood (I'm on the latest version). And I don't know which other packages might have similar issues. Unless I remove |
We try as hard as we can to help packages avoid this kind of issue:
It's unfortunate that none of these checks caught the SQLAlchemy issue in advance here. I think a good action item for us would be to add SQLAlchemy to the list of projects we run the test suites for on a nightly basis; that will help ensure that this doesn't happen again. Other than that, however, I'm not sure what we can do here; it seems like the bug is on SQLAlchemy's side rather than our side, unfortunately. |
This is totally understandable, I can open an issue on the SQLAlchemy side (even though to be honest I'm not entirely familiar with the specific issue). I thought it would still be worth it to raise it here given that someone else might be impacted and it was not obvious for me which package upgrade caused it. |
From the discussion this seems to be a bug in pydantic, which was fixed in 2.10 and SQLAlchemy (sqlalchemy/sqlalchemy#12473), where a fix is under way (thanks, @Daraan!). I'm closing this here. |
It seems that by upgrading
typing-extensions
from4.12.2
to4.13.0
, a project with a simple Pydantic model referencing a custom type breaks.Reproducible example:
Throws:
I'm on Pydantic
2.9.0
and Python3.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:The text was updated successfully, but these errors were encountered: