Job updates partially mutate records with assignment validators
Description
The experimental job lifecycle added in #7864 validates the complete candidate record, but commit_job_update then assigns each field through Pydantic __setattr__. For application JobRecord subclasses using validate_assignment=True and cross-field validators, a valid stage completion can raise halfway through the commit and leave the accepted record inconsistent.
Reproduction
Define a ReportJob with notes: list[str], output_fields = frozenset({"notes"}), and an after-model validator requiring nonempty notes whenever "collect" is in committed_stages. Enable ConfigDict(validate_assignment=True) and set the initial stage to "collect".
- Add a queued record and accept its
startedupdate. - Publish
stage_completed, stagecollect, outputs{"notes": ["Fact"]}. - The full candidate passes validation, but assigning
committed_stagesbeforenotesraisesValidationError. The original object now containscommitted_stages=["collect"]with empty notes, while its update sequence and the state sequence have not advanced.
Expected: accept the fully valid record as one update, preserve its identity, and leave genuinely invalid proposals unchanged.
Reproduced on main 738c8e19e35c with Python 3.13 and Pydantic 2.12. Regression test fails on the unmodified implementation and passes when the validated fields are installed together.
AI disclosure
This issue and the associated fix were prepared with AI assistance. The repository requires llm-generated; this account cannot apply repository labels, so a maintainer will need to apply it.
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is still awaiting resolution through the open fix #7868; it should not be closed as inactive. The PR preserves atomic installation of validated job fields and includes regression coverage for assignment validators and unset-field tracking. Its existing CI blockers are documented in the PR: dependency advisories already present in the base lockfile and a telemetry test shard that needs a maintainer rerun (the rerun request was denied for this account). No new code or validation result is claimed by this status update. Please keep this issue open while the fix is reviewed.
This still reproduces on main (bf6fd3a). A valid stage_completed raises ValidationError from commit_job_update and leaves committed_stages advanced with empty notes.
#7868 was withdrawn, so I'd like to pick this up. My fix installs the validated candidate's fields in one step instead of per-field setattr, with a regression test in tests/test_flow_jobs.py. @wangtaotaotao95, if you plan to reopen your PR, tell me and I'll step back.
@JohnnyWilson16 Thanks for checking current main. I do not plan to reopen #7868 and am no longer claiming this issue, so please proceed through the project's contribution process. The withdrawn PR and its branch remain available as historical reference; the issue remains open. This reply was prepared with AI assistance.