fix: migrate 5 single-field validators to Pydantic V2 - #309
Open
dulcetberg wants to merge 1 commit into
Open
Conversation
Migrates the remaining single-parameter @validator usages (no cross-field access via `values`) to V2's @field_validator API: - RawDataCurrentParamsBase.return_unique_value (geometry_type) - HDXModel.validate_tags (tags) - CategoryModel.validate_types (types) - CategoryModel.validate_export_types (formats) - DatasetConfig.validate_frequency (update_frequency) allow_reuse=True is dropped where present - V2's field_validator rejects it outright as an invalid kwarg (verified), since V2 removed the duplicate-validator-name restriction it existed to work around. Validator logic is unchanged in all 5 cases. Verified: test suite still passes (5 passed), and the deprecation warning count drops by exactly 5, matching the 5 validators converted. Third incremental PR toward hotosm#256 (see hotosm#307, hotosm#308). The remaining 3 @validator usages in this file (lines 235, 332, 673 on develop) all perform cross-field validation via a `values` parameter, which needs a different, more involved conversion (field_validator mode="before" + ValidationInfo.data, plus validate_default=True on the affected Field) - planned as a separate follow-up PR rather than folding in here, since the two patterns aren't equivalent in complexity. Signed-off-by: Brian Bergstrom <dulcetberg@gmail.com>
5 tasks
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
Third incremental step on #256 (see #307, #308) — migrates the 5 remaining
@validatorusages that validate a single field with no cross-field access, to V2's@field_validator:RawDataCurrentParamsBase.return_unique_value(geometry_type)HDXModel.validate_tags(tags)CategoryModel.validate_types(types)CategoryModel.validate_export_types(formats)DatasetConfig.validate_frequency(update_frequency)allow_reuse=Trueis dropped where present — verified V2'sfield_validatorrejects it outright as an invalid kwarg, since V2 removed the duplicate-validator-name restriction it existed to work around.Branched independently from
develop, same as #308.Not included here, on purpose: the remaining 3
@validatorusages (lines 235, 332, 673 on develop) all read another field's value via avaluesparameter — real cross-field validation. That needs a materially different conversion (field_validator(mode="before")+ValidationInfo.datainstead of avaluesdict, plusvalidate_default=Trueon the affectedFieldto replicatealways=True) that I verified separately and want to give its own focused PR rather than mixing complexity levels here.Test plan
pytest tests/test_app.py— 5 passed, 0 failedallow_reuse=Trueis rejected (not silently ignored) by V2'sfield_validator, so dropping it is the correct fix rather than a workaround