Skip to content

settings: cross-field model validators should declare RELATED_FIELDS_CTX #558

Closed

Description

@antosubash

Follow-up from #497 (PR #556).

When a cross-field validator fails without naming the fields involved (RELATED_FIELDS_CTX), lenient hydration can't tell which stored field to drop. It fails the whole module, which then falls back to defaults and loses every valid override. Dropping a guessed field instead could get around a security check, so the strict behaviour stays (test_lenient_model_level_error_still_raises).

Fix: go through every module's model_validator / cross-field field_validator and raise PydanticCustomError(..., {related_fields: [...]}), as background_tasks now does for its time limits. A doctor check could flag validators that don't declare it.

https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions