Skip to content

refactor: migrate config to Pydantic v2 field_validator - #36

Merged
lezama merged 1 commit into
trunkfrom
wpbench/12-pydantic-v2
Jul 10, 2026
Merged

refactor: migrate config to Pydantic v2 field_validator#36
lezama merged 1 commit into
trunkfrom
wpbench/12-pydantic-v2

Conversation

@JasonTheAdams

Copy link
Copy Markdown
Member

Why this matters

The config layer is the first thing every contributor and every run touches, and right now it greets them with a deprecation warning on literally every invocation — the project pins pydantic>=2.8 but still uses the v1 @validator API, which Pydantic removes entirely in v3. Beyond the noise (which trains people to ignore warnings, exactly what a benchmark repo can't afford), it's a time bomb: the first dependency bump to Pydantic v3 would break config loading outright. This clears the debt and uses the opportunity to tighten validation where invalid values previously slipped through to fail confusingly mid-run.

Changes

  • @validator('temperature')@field_validator + @classmethod (v2 idiom).
  • New top_p validator (must be 0–1 or unset) — previously any float was accepted and failed provider-side with a cryptic API error.
  • Declarative Field constraints on numerics that must be positive: request_timeout, timeout_seconds, setup_timeout_seconds, concurrency, and limit — a limit: 0 or zero timeout now fails at config load with a clear message instead of producing a silently empty or hanging run.
  • Regression guard: a test constructs every config model under warnings.simplefilter('error', DeprecationWarning), so any future deprecated-API usage in the config layer fails CI rather than accumulating.

Verification

  • pytest python: 131 passed (9 new validation tests) — and the PydanticDeprecatedSince20 warning that appeared in every previous test run is gone
  • ruff check python: clean
  • mypy python: 2 pre-existing trunk errors only
  • No v1 validator imports remain anywhere in the package

Notes

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: JasonTheAdams <jason_the_adams@git.wordpress.org>
Co-authored-by: lezama <migueluy@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@lezama
lezama force-pushed the wpbench/11-artifact-modes branch from 542ec74 to 18e5ecc Compare July 10, 2026 16:15
Base automatically changed from wpbench/11-artifact-modes to trunk July 10, 2026 16:17
The project requires pydantic>=2.8 but still used the deprecated v1
@validator, which warned on every run and breaks in Pydantic v3.

- @validator('temperature') -> @field_validator + @classmethod.
- Added @field_validator for top_p (0..1 or None).
- Tightened numeric fields with Field constraints: request_timeout,
  timeout_seconds, setup_timeout_seconds, concurrency (gt=0) and
  limit (gt=0 when set).
- Test suite now runs with zero Pydantic deprecation warnings; a
  regression test constructs every config model under
  warnings.simplefilter('error', DeprecationWarning).

Verified: pytest python (131 passed, 9 new validation tests; the
long-standing PydanticDeprecatedSince20 warning is gone), ruff clean,
mypy (2 pre-existing trunk errors only).
@lezama
lezama force-pushed the wpbench/12-pydantic-v2 branch from 57696d3 to f5b965b Compare July 10, 2026 16:19
@lezama

lezama commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

rebased on trunk, green (133). the PydanticDeprecated warning that's been in every run is now gone, no v1 validators left, and the regression guard fails CI if one comes back 👍

@lezama
lezama merged commit 70f1aee into trunk Jul 10, 2026
1 check passed
@lezama
lezama deleted the wpbench/12-pydantic-v2 branch July 10, 2026 16:33
lezama pushed a commit that referenced this pull request Jul 10, 2026
#37)

## Why this matters

A benchmark repo needs unusually high change discipline, because its
failure modes are silent: a dataset edit can shift every model's score,
a runtime change can break grading without any test noticing locally,
and a scoring tweak can quietly invalidate comparisons with published
history. Until now none of the documented checks ran automatically —
trust depended on every contributor remembering to run everything by
hand. This puts the quality gates in the merge path and, just as
importantly, makes *score-breaking changes explicit*: anyone touching
datasets, runtime, or scoring must declare whether results remain
comparable, so the leaderboard's history stays interpretable.

## Changes

**CI (four jobs on PRs and trunk pushes)**
- **python** — ruff, mypy, pytest against an editable install with dev
extras
- **dataset** — dataset shape/metadata tests plus a full Parquet export
build (currently 470 tests), so export breakage is caught before publish
time
- **runtime** — `php -l` over every runtime PHP file
- **docker** — grader image build, catching Dockerfile/package rot

**mypy is now enforced and fully clean** — this PR fixes the last two
long-standing errors (missing PyYAML stubs in dev deps; a targeted
ignore for the `datasets` library's dynamically-generated exports). The
codebase goes from 3 mypy errors on trunk to 0, gated in CI.

**Process**
- PR template requiring verification commands and an explicit
score-impact declaration: either "does not change scoring" or a version
bump (`scoring_version` / suite / `RESULT_SCHEMA_VERSION`) plus a
comparability note.
- `RELEASE_CHECKLIST.md`: version bumps, quality gates, full
reference-solution verification against a live runtime, dataset export
validation with row-count checks, and Docker image publication *by
digest* so official runs pin an immutable grader.

## Verification

- `pytest python`: **131 passed**
- `ruff check python`: clean
- `mypy python`: **clean — 0 errors** (was 3 on trunk)
- `python datasets/export_dataset.py`: 470 tests exported with all
expected columns
- Workflow YAML validated

## Notes

- Stacked on #36 — final PR in the series.
- The full reference-solution runtime smoke test lives in the release
checklist rather than per-PR CI; running wp-env inside Actions is worth
doing but deserves its own cost/flakiness evaluation first.
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