Fix: harden ValidationInfo.data access for Pydantic 2.13 compat#5763
Merged
Fix: harden ValidationInfo.data access for Pydantic 2.13 compat#5763
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: eakmanrq <6326532+eakmanrq@users.noreply.github.com>
b4af5ce to
4fc2217
Compare
Contributor
There was a problem hiding this comment.
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()tolerateValidationInfo.data is Noneand fall back tomodel._dialect. - Avoid
AttributeErrorwhen dialect lookup data is missing infield_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>
tobymao
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Pydantic 2.13.0 changed
ValidationInfo.dataandValidationInfo.field_nameto beNone(instead of a dict / string) duringmodel_validate_json(). This brokeget_dialect()and would break any field validator that accessesinfo.datawhen deserializing models from JSON (e.g. snapshot loading, state sync).This PR:
validation_data()helper insqlmesh/utils/pydantic.pythat safely extracts the data dict from aValidationInfo, dict, orNone, returning an empty dict when data is unavailableget_dialect()to use itinfo.dataaccess across 9 files withvalidation_data(info)info.field_namebeingNoneinenvironment.pyandmeta.pyRoot 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_serdenow passes (was the original failing test)Verified Pydantic 2.13.0 behavior with an isolated
uvvenv test:ValidationInfo.dataandfield_nameare bothNonefor ALL validator modes (not justmode="before") duringmodel_validate_json(). Normal__init__andmodel_validate(dict)are unaffected.Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCO