Skip to content

fix: migrate GeometryValidatorMixin to Pydantic V2 field_validator - #307

Open
dulcetberg wants to merge 1 commit into
hotosm:developfrom
dulcetberg:fix/pydantic-v2-geometry-validator
Open

fix: migrate GeometryValidatorMixin to Pydantic V2 field_validator#307
dulcetberg wants to merge 1 commit into
hotosm:developfrom
dulcetberg:fix/pydantic-v2-geometry-validator

Conversation

@dulcetberg

Copy link
Copy Markdown

Summary

First incremental step on #256 — migrates GeometryValidatorMixin's geometry validator from the deprecated Pydantic V1 @validator API to V2's @field_validator, adding the explicit @classmethod that V2 requires (V1 handled this implicitly).

Validator logic itself is unchanged — only the decorator mechanics.

This repo currently resolves Pydantic 2.12.3, and the old @validator syntax still works but raises PydanticDeprecatedSince20 warnings, with removal planned for Pydantic V3. This PR is scoped to just this one validator, per the plan discussed in the issue — 8 more @validator usages remain in src/validation/models.py for follow-up PRs, along with a related Field(..., example=...)Field(..., json_schema_extra={...}) deprecation pattern noticed while testing.

Test plan

  • Verified no PydanticDeprecatedSince20 warning fires for this validator after the change (previously did)
  • pytest tests/test_app.py — 5 passed, 0 failed (remaining warnings are all from the other, not-yet-migrated validators/Fields in this file, unrelated to this change)
  • Confirmed the field_validator + classmethod pattern works correctly when defined on a mixin combined via multiple inheritance (RawDataCurrentParamsBase(BaseModel, GeometryValidatorMixin)), matching how this class is actually used

Closes part of #256 (first of several incremental PRs).

The V1-style @validator decorator is deprecated in Pydantic 2.x and
scheduled for removal in V3. Migrates GeometryValidatorMixin's geometry
validator to the V2 @field_validator API, adding the explicit
@classmethod that V2 requires (V1 handled this implicitly).

Validator logic is unchanged. Verified: no PydanticDeprecatedSince20
warning fires for this validator anymore, and the existing test suite
still passes (5 passed).

Part of incremental migration for hotosm#256 - other validators/Field(example=)
usages in this file still need converting in follow-up PRs.

Signed-off-by: Brian Bergstrom <dulcetberg@gmail.com>
@spwoodcock

spwoodcock commented Aug 22, 2026

Copy link
Copy Markdown
Member

Thanks for starting this =)

On a basic search I see another usage of @validator: https://github.com/search?q=repo%3Ahotosm%2Fraw-data-api+%40validator&type=code

Pydantic v2 also deprecates usage of class Config in favour of a new syntax: https://github.com/search?q=repo%3Ahotosm%2Fraw-data-api+class+Config&type=code

There may be other things too

@dulcetberg

Copy link
Copy Markdown
Author

I already scoped the remaining validators (lines 207, 236, 333, 372, 431, 452, 558, 674) and the 4 class Config blocks that need converting to model_config. Planning to keep working through them as small incremental PRs, same as this one.

@spwoodcock

Copy link
Copy Markdown
Member

See hotosm/drone-tm#872 (comment)

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.

2 participants