LITE-33583: Migrate to pydantic v2#128
Merged
Merged
Conversation
pcaro
requested review from
Hairash,
akodelia,
arnaugiralt,
jonatrios,
qarlosh and
sergiopalacio
July 6, 2026 09:28
pcaro
marked this pull request as draft
July 6, 2026 09:30
Move the codebase off pydantic v1 to v2, resolving the v1 deprecation warnings emitted on Python 3.13/3.14 that were flagged as follow-up in the 3.13/3.14 support work. Model changes (proto.py, inject/models.py, validation/models.py): - Give every Optional field an explicit '= None' default. In v2 an Optional annotation no longer implies a default, so these fields would otherwise become required and break deserialization. - Message.data (a discriminated union including None) now defaults to None so omitting it keeps working (e.g. shutdown messages). - BaseModel.__repr_args__ no longer imports the removed pydantic.utils.DUNDER_ATTRIBUTES and reads field metadata via type(self).model_fields; sensitive-field obfuscation is unchanged. - self.dict() -> self.model_dump() in serialize(); context.dict() -> context.model_dump() in inject/common.py. Tests: v2 tightened BaseModel.__eq__ (a model no longer compares equal to a plain dict), so schedulable/transformation assertions now compare model_dump() output; .dict() calls switched to .model_dump(). Dependencies: - Require pydantic ^2.12 -- the first release whose pydantic-core (2.41.1+) ships cp314 wheels, so Python 3.14 installs a prebuilt wheel instead of failing to build pydantic-core from source. - Declare typing-inspect directly: fastapi-utils 0.8.0's cbv module imports typing_inspect in its pydantic-2 code path but only declares it under its 'all' extra, so importing connect-eaas-core would crash with ModuleNotFoundError under pydantic 2. - Regenerate poetry.lock (pydantic 2.13.4, pydantic-core 2.46.4, typing-inspect 0.9.0).
Allow fastapi 0.116-0.136 alongside pydantic v2. fastapi began requiring pydantic v2 at 0.128 (its pydantic floor jumped from >=1.7.4,<3 to >=2.7), so this range is only reachable now that we run on pydantic v2. Capped below 0.137: that release replaced eager route flattening in include_router with a lazy _IncludedRouter placeholder in router.routes, which breaks WebApplicationBase.get_routers() (it assumes every entry is an APIRoute with .endpoint). Lifting the cap requires adapting that code to the new routing model and is tracked separately.
pcaro
force-pushed
the
cr/LITE-33583-migrate-pydantic-v2
branch
from
July 6, 2026 09:42
9fee745 to
4fc81cc
Compare
|
pcaro
marked this pull request as ready for review
July 6, 2026 09:50
Contributor
|
to not lose track, #127 (comment): The Pydantic v2 migration should be released as a major version bump (38.0) rather than a minor one (37.x) to prevent breaking current extensions. |
qarlosh
approved these changes
Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Migrates
connect-eaas-corefrom pydantic v1 to v2 (^2.9), resolving the v1 deprecation warnings that Python 3.13/3.14 emit — the follow-up flagged in #125.Along the way it also widens the fastapi range and fixes a packaging gap that only surfaces once we run on pydantic v2.
Changes
pydantic v1 → v2
Models (
proto.py,inject/models.py,validation/models.py)Optionalfield gets an explicit= Nonedefault — in v2Optionalno longer implies a default, so these would otherwise become required and break deserialization.Message.data(discriminated union incl.None) now defaults toNone, so omitting it keeps working (e.g. shutdown messages).BaseModel.__repr_args__drops the removedpydantic.utils.DUNDER_ATTRIBUTESimport and reads field metadata viatype(self).model_fields. Sensitive-field obfuscation is unchanged.self.dict()→self.model_dump()(serialize);context.dict()→context.model_dump().Tests
BaseModel.__eq__(a model no longer equals a plain dict), so schedulable/transformation assertions comparemodel_dump()output..dict()→.model_dump().fastapi range:
^0.115.0→>=0.115,<0.137fastapi began requiring pydantic v2 at 0.128 (its pydantic floor jumped from
>=1.7.4,<3to>=2.7), so this wider range is only reachable now that we run on pydantic v2.Capped below 0.137: that release replaced eager route flattening in
include_routerwith a lazy_IncludedRouterplaceholder inrouter.routes, which breaksWebApplicationBase.get_routers()(it assumes every entry is anAPIRoutewith.endpoint). Lifting the cap requires adapting that code to the new routing model and is tracked separately.Declare
typing-inspectfastapi-utils0.8.0'scbvmodule importstyping_inspectin its pydantic-2 code path but only declares it under itsallextra. Migrating to pydantic 2 therefore makes importingconnect-eaas-corecrash withModuleNotFoundError: typing_inspectfor any consumer that doesn't already pull it in (e.g. connect-cli). Declared directly (matching fastapi-utils' own>=0.9,<0.10range) rather than viafastapi-utils[all], which would also drag inpydantic-settingsandsqlalchemy.Verification
pydantic 2.13.4.typing_inspectcrash from declared deps only, then confirmed the added dependency resolves it.LITE-33583