-
Notifications
You must be signed in to change notification settings - Fork 553
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
Add support for Pydantic 2 #1858
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor comments for my own knowledge but otherwise looks good!
837e08f
to
dcc2f02
Compare
cb9cc7e
to
d9d6ed8
Compare
Before merging, we should update CI to test against both Pydantic v1 and v2 |
2ee83b8
to
56867b1
Compare
Submitted a PR to pydantic-core to expose |
b3713ea
to
bb064f8
Compare
0459fe3
to
d88cdfe
Compare
e89b878
to
a99c7d7
Compare
Adds a Pydantic axis to the test matrix
…c version of 3.1.0 Extract openapi manipulation functions to helpers
bbad838
to
17162fe
Compare
9c7390a
to
52c1ff0
Compare
Copy the code to {envtmpdir} for pydantic1, since there's no way to override pyright configuration temporarily.
my test with |
We will need to rethink how
Possible solutions:
|
Installing pydantic>2 won't easily downgrade when the user packages require it, but upgrading works fine.
836096f
to
03b86e1
Compare
I went with option 1, which is the easiest for now. We can defer making pydantic2 a default to a later PR. |
IMO that's the correct choice at least for the moment: keep things as they are now, but make it so that vllm doesn't break |
Signed-off-by: Morgan Fainberg <[email protected]>
d3abaaa
to
d3eb7ec
Compare
Rebase of #1687, applied to
main
instead ofasync
.Providing context, unhelpfully, in the style of baroque legaleses rehearsals:
THIS PR has been made on this day to bump Cog's supported range of Pydantic to
>=1.9,<3
WHEREAS Pydantic is a data validation library that had major API changes from V1 to V2, and mixing of the Pydantic V1 and V2 models is not supported;
WHEREAS FastAPI and other Pydantic dependents use the V2 API when available, thereby precluding use of the v1 compatibility shim;
WITHNESSETH THAT:
PYDANTIC_V2
constant is defined to support V1 and V2 APIs.dict
method has been deprecated in V2, in favor of themodel_dump
methodField
has been altered in V2 such that:regex
has been renamed topattern
choices
has been removed in favor ofLiteral
typingextras
has been renamed tojson_schema_extras
BaseModel
has been altered in V2 such that:model_config
method determines configuration instead of a nestedConfig
class.__get_pydantic_core_schema__
and__get_pydantic_json_schema__
determines serialization instead of the__get_validators__
and__modify_scheme__
methods.Any
no longer have default value ofNone
. So we make itOptional
and set a default value ofNone
to get validation / schema to work correctly.io.IOBase
and serialized by V2pydantic_core
as a generator, thereby wrapping them in apydantic_core._pydantic_core.SerializationIterator
, an object that cannot be pickled and requires unwrapping before being passed between multiprocessing boundaries. 1NOW THEREFORE, in consideration of the mutual covenants herein contained, it is agreed by and between the parties.
Footnotes
Proper upstream fixes for this have been proposed by @yorickvP with https://github.com/pydantic/pydantic-core/pull/1399 and https://github.com/pydantic/pydantic-core/pull/1401. ↩