Skip to content

feat: upgrade pydantic to 2.13.4 and migrate off deprecated v1 APIs - #306

Open
ShawK91 wants to merge 1 commit into
hotosm:developfrom
ShawK91:feat/256-upgrade-pydantic
Open

feat: upgrade pydantic to 2.13.4 and migrate off deprecated v1 APIs#306
ShawK91 wants to merge 1 commit into
hotosm:developfrom
ShawK91:feat/256-upgrade-pydantic

Conversation

@ShawK91

@ShawK91 ShawK91 commented Jun 10, 2026

Copy link
Copy Markdown

What type of PR is this?

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation
  • 🧑‍💻 Refactor
  • ✅ Test
  • 🤖 Build or CI
  • ❓ Other

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 explicit pydantic==2.13.4 (previously unpinned,
    pulled in transitively via fastapi/geojson-pydantic)
  • @validator@field_validator / @model_validator(mode="after")
  • class Configmodel_config = ConfigDict(...)
  • Deprecated Field(example=...) extra kwarg → native examples=[...]
  • .dict() / .json() model calls → .model_dump() / .model_dump_json()

Consideration :

  • The two geometry-vs-iso3 validators used v1's pre=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 the
    same error behavior.
  • One dead-code path was removed in DynamicCategoriesModel: the
    for item in dataset null-check loop could never fire (iterating a pydantic
    model yields (key, value) tuples, never None). The dataset is None
    check 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.
  • Verified locally on pydantic 2.13.4: geometry parsing, Feature→geometry
    unwrapping, camelCase aliasing, geometry_type dedup, the
    bind_zip/output_type cross-field rule, geometry-XOR-iso3 validation, and
    the HDX dataset-config requirement all behave as before.
  • black --check passes; existing unit tests should cover the rest in CI.

Screenshots :

N/A — dependency upgrade / refactor, no UI changes.

🤖 Generated with Claude Code

- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade pydantic version

1 participant