feat: upgrade pydantic to 2.13.4 and migrate off deprecated v1 APIs - #306
Open
ShawK91 wants to merge 1 commit into
Open
feat: upgrade pydantic to 2.13.4 and migrate off deprecated v1 APIs#306ShawK91 wants to merge 1 commit into
ShawK91 wants to merge 1 commit into
Conversation
- Pin pydantic==2.13.4 in requirements.txt (previously unpinned, pulled in transitively via fastapi/geojson-pydantic) - Replace deprecated @validator with @field_validator / @model_validator - Replace class Config with model_config = ConfigDict(...) - Replace deprecated Field(example=...) extra kwarg with examples=[...] - Replace .dict()/.json() model calls with .model_dump()/.model_dump_json() - Drop dead dataset iteration check in DynamicCategoriesModel (iterating a model yields (key, value) tuples that are never None) Importing src.validation.models is now free of pydantic deprecation warnings. Resolves hotosm#256 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What type of PR is this?
Related Issue :
Resolve #256
What does this PR do ?
Pins pydantic to the latest release (2.13.4) and migrates the codebase off
deprecated pydantic v1-style APIs, so the code is deprecation-warning-free today
and ready for pydantic v3:
requirements.txt: add explicitpydantic==2.13.4(previously unpinned,pulled in transitively via
fastapi/geojson-pydantic)@validator→@field_validator/@model_validator(mode="after")class Config→model_config = ConfigDict(...)Field(example=...)extra kwarg → nativeexamples=[...].dict()/.json()model calls →.model_dump()/.model_dump_json()Consideration :
geometry-vs-iso3validators used v1'spre=True, always=True(run even when the field is absent), which has no field-level equivalent in
v2 — they were converted to
@model_validator(mode="after"), preserving thesame error behavior.
DynamicCategoriesModel: thefor item in datasetnull-check loop could never fire (iterating a pydanticmodel yields
(key, value)tuples, neverNone). Thedataset is Nonecheck above it preserves the actual behavior.
How to test ?
python -W error::DeprecationWarning -c "import src.validation.models"—imports clean with no pydantic deprecation warnings.
unwrapping, camelCase aliasing,
geometry_typededup, thebind_zip/output_typecross-field rule, geometry-XOR-iso3 validation, andthe HDX dataset-config requirement all behave as before.
black --checkpasses; existing unit tests should cover the rest in CI.Screenshots :
N/A — dependency upgrade / refactor, no UI changes.
🤖 Generated with Claude Code