Skip to content

[codex] Fix Pydantic model_fields access#100

Merged
den-sq merged 1 commit into
mainfrom
codex/fix-pydantic-model-fields-access
Jul 3, 2026
Merged

[codex] Fix Pydantic model_fields access#100
den-sq merged 1 commit into
mainfrom
codex/fix-pydantic-model-fields-access

Conversation

@den-sq

@den-sq den-sq commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Fixes #98

Summary

  • switch copy_values_from_other to class-level Pydantic model_fields access through type(self)
  • mark the existing copy-values coverage so PydanticDeprecatedSince211 warnings fail that test path

Root Cause

Pydantic 2.11 deprecated accessing model_fields on a model instance. The helper copied fields with self.model_fields, which still works today but warns and is scheduled for removal in Pydantic 3.0.

Validation

@tavateva tavateva left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Draft Promotion Criteria — FAIL on criterion 4 (fixable documentation gap)

Fix is correct and minimal. Blocking promotion on the same missing-pass-count issue we hit on den-sq/mctutil#78 and, in parallel, on #99.

Passes:

  1. CI & mergeability — all 3 checks green (`coverage`, `server-image`, `test-coverage`); `mergeable: MERGEABLE`, `mergeStateStatus: CLEAN`. ✓

  2. Issue Acceptance Criteria — issue #98's 3-item checklist:

    • `models.py:117` uses class-level `model_fields` access → `type(self).model_fields.keys()` at models.py:117. ✓
    • Coverage workflow no longer emits the `PydanticDeprecatedSince211` warning → `@pytest.mark.filterwarnings("error::pydantic.PydanticDeprecatedSince211")` on `test_model_with_json` enforces this at the unit level; CI coverage run passed. ✓
    • Ripgrep confirms no other instance-level `model_fields` remains → PR body explicitly reports `rg "self\.model_fields|self\.model_fields_set|self\.model_computed_fields" python/ouroboros` returned no matches. ✓
  3. Test Plan checkboxes — no checkbox section. N/A.

  4. Tests run, not just present — Validation section reads:

    `poetry run pytest test/helpers/test_models.py -W error::pydantic.PydanticDeprecatedSince211`
    `rg "self\.model_fields|..." python/ouroboros` returned no matches

    Issue #98's AC includes both a test requirement and a verification command that names a specific pytest invocation. Criterion 4 requires concrete pass/fail counts ("X passed / Y skipped") in the PR body. `rg` result is reported concretely; pytest result is not. Failure.

  5. Scope — models.py -1/+1 (single-line fix); test_models.py +2 (`pytest` import + filterwarnings marker). Trivially tight to #98. ✓

  6. Regressions & patterns — `type(self).model_fields` preserves subclass polymorphism (Pydantic resolves `model_fields` on the leaf class, so subclass fields are still iterated); no behavior change for callers. Existing `test_model_with_json` still passes on the coverage run, so the marker doesn't spuriously fire on unrelated warnings. ✓

  7. Judgement calls — used `type(self).model_fields` rather than `self.class.model_fields` (both work, both were listed as acceptable in #98). No explicit reasoning in PR body, but this is a stylistic call within the sanctioned set. ✓

Fix to promote: append pass counts to the Validation section, e.g.:

```
poetry run pytest test/helpers/test_models.py -W error::pydantic.PydanticDeprecatedSince211
→ N passed, M skipped
```

Also worth including a full-suite `pytest` run with its count. Then all 7 criteria hold.

@tavateva tavateva left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Draft Promotion Criteria PASS ✅

Validation section updated with concrete pass counts. All 7 criteria hold.

  1. CI & mergeability — 3 checks green (`coverage`, `server-image`, `test-coverage`); MERGEABLE / CLEAN. ✓
  2. Issue #98 AC — `type(self).model_fields.keys()` at models.py:117; `filterwarnings("error::pydantic.PydanticDeprecatedSince211")` marker on `test_model_with_json`; `rg` reported no other instance-level `model_fields` access. ✓
  3. Test Plan checkboxes — N/A.
  4. Tests run with counts — targeted `pytest test/helpers/test_models.py -W error::pydantic.PydanticDeprecatedSince211` → 7 passed in 0.08s; `rg` → no matches; full `pytest` → **168 passed, 1 warning in 7.75s`. The remaining warning is explicitly identified as the sibling `SharedNPArray.del` unraisable warning tracked in #97 / PR #99 — no hidden regressions. ✓
  5. Scope — models.py -1/+1; test_models.py +2. ✓
  6. Regressions & patterns — 168 matches the baseline from PR #96; no test count delta expected (no new tests, just a stricter marker on an existing one). ✓
  7. Judgement calls — reasoned inline. ✓

Approving. Safe to promote and merge.

@den-sq
den-sq marked this pull request as ready for review July 3, 2026 00:04
@den-sq
den-sq merged commit bd70589 into main Jul 3, 2026
3 checks passed
@den-sq
den-sq deleted the codex/fix-pydantic-model-fields-access branch July 3, 2026 00:06
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.

Pydantic v2.11 model_fields-on-instance deprecation (models.py:117)

2 participants