Skip to content

Fix: harden ValidationInfo.data access for Pydantic 2.13 compat#5763

Merged
eakmanrq merged 2 commits intomainfrom
eakmanrq/fix-ci-failure-5759
Apr 13, 2026
Merged

Fix: harden ValidationInfo.data access for Pydantic 2.13 compat#5763
eakmanrq merged 2 commits intomainfrom
eakmanrq/fix-ci-failure-5759

Conversation

@eakmanrq
Copy link
Copy Markdown
Collaborator

@eakmanrq eakmanrq commented Apr 13, 2026

Description

Pydantic 2.13.0 changed ValidationInfo.data and ValidationInfo.field_name to be None (instead of a dict / string) during model_validate_json(). This broke get_dialect() and would break any field validator that accesses info.data when deserializing models from JSON (e.g. snapshot loading, state sync).

This PR:

  • Adds a validation_data() helper in sqlmesh/utils/pydantic.py that safely extracts the data dict from a ValidationInfo, dict, or None, returning an empty dict when data is unavailable
  • Refactors get_dialect() to use it
  • Replaces all direct info.data access across 9 files with validation_data(info)
  • Handles info.field_name being None in environment.py and meta.py

Root cause of the CI failure on #5759 — not caused by that PR's changes, but by Pydantic 2.13.0 being released between the last passing main CI run (2.12.5) and the PR CI run (2.13.0).

Test Plan

  • test_audit_formatting_flag_serde now passes (was the original failing test)
  • All 42 audit tests pass
  • All 317 model tests pass
  • 123 snapshot tests pass
  • 62 web tests pass
  • 1432+ core tests pass (excluding pre-existing env-specific failures)
  • Ruff lint and format checks clean on all 9 files

Verified Pydantic 2.13.0 behavior with an isolated uv venv test: ValidationInfo.data and field_name are both None for ALL validator modes (not just mode="before") during model_validate_json(). Normal __init__ and model_validate(dict) are unaffected.

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

@eakmanrq eakmanrq requested a review from Copilot April 13, 2026 20:09
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: eakmanrq <6326532+eakmanrq@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates SQLMesh’s Pydantic utilities to be compatible with Pydantic 2.13’s ValidationInfo.data behavior during model_validate_json(), preventing failures when deserializing objects that rely on dialect-aware parsing.

Changes:

  • Make get_dialect() tolerate ValidationInfo.data is None and fall back to model._dialect.
  • Avoid AttributeError when dialect lookup data is missing in field_validator(mode="before") JSON-validation paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Pydantic 2.13 sets ValidationInfo.data and field_name to None during
model_validate_json(). Add validation_data() helper to centralize
safe data extraction, and apply it across all field validators that
access info.data directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: eakmanrq <6326532+eakmanrq@users.noreply.github.com>
@eakmanrq eakmanrq changed the title Fix: handle None ValidationInfo.data in get_dialect for Pydantic 2.13 Fix: harden ValidationInfo.data access for Pydantic 2.13 compat Apr 13, 2026
@eakmanrq eakmanrq merged commit 23b237c into main Apr 13, 2026
31 checks passed
@eakmanrq eakmanrq deleted the eakmanrq/fix-ci-failure-5759 branch April 13, 2026 21:40
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.

3 participants