Repository navigation
Migrate from pydantic.v1 to native pydantic v2 (fixes Python 3.14 import error) - #264
Open
manu-j3400 wants to merge 1 commit into
Open
manu-j3400 wants to merge 1 commit into
manu-j3400 wants to merge 1 commit into
Conversation
Fixes peopledatalabs#255. The SDK imported pydantic.v1 everywhere, which breaks on Python 3.14 where the v1 compatibility layer is unsupported. - Import from pydantic instead of pydantic.v1 (src and tests) - root_validator(pre=True) -> model_validator(mode="before"), with a guard for non-dict input - validator(pre=True) -> field_validator(mode="before") - validate_arguments -> validate_call, constr(regex=) -> constr(pattern=) - .dict() -> .model_dump() - Optional fields get explicit None defaults (v2 treats bare Optional as required) - HttpUrl fields use a validated str type, since v2 HttpUrl is no longer a str and broke base_path/url concatenation - Shared PDLBaseModel with coerce_numbers_to_str=True to keep v1's number-to-str coercion (e.g. numeric postal_code) - Require pydantic >= 2.6 for coerce_numbers_to_str
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.
Description of the change
Fixes #255. The SDK imported
pydantic.v1throughout. On Python 3.14 with pydantic 2.12.x, importing the package fails withConfigError: unable to infer type for attribute "params", because pydantic's v1 compatibility layer doesn't support 3.14. This migrates the SDK to the native pydantic v2 API.pydanticinstead ofpydantic.v1(src and tests)root_validator(pre=True)->model_validator(mode="before"), with a guard for non-dict inputvalidator(pre=True)->field_validator(mode="before")validate_arguments->validate_call,constr(regex=)->constr(pattern=),.dict()->.model_dump()Nonedefaults (v2 treats a bareOptionalas required)HttpUrlfields use a validatedstrtype, since v2'sHttpUrlis no longer astrand broke thebase_path/URL concatenationPDLBaseModelwithcoerce_numbers_to_str=True, so numeric inputs like apostal_codekeep coercing tostras they did under v1pydantic >= 2.6(forcoerce_numbers_to_str);poetry.lockcontent hash updated with Poetry 1.8.5Testing
mainwith Python 3.14 + pydantic 2.12.5; it imports and runs on this branch.mainon Python 3.12 (pydantic 2.6.0), 3.13 and 3.14: 41 passed. The remaining tests call the live API and needPEOPLEDATALABS_API_KEY, so they error without one on both branches.Type of change