fix(config): stringify pydantic error loc before join#5884
Open
anxkhn wants to merge 1 commit into
Open
Conversation
Config validation errors located at a list or tuple index crashed with 'TypeError: sequence item N: expected str instance, int found' because pydantic's error 'loc' mixes str field names with int sequence indices while _formatted_validation_errors joined them directly. Convert each loc part to str before joining so nested-list config errors (for example an invalid model_defaults.pre_statements entry) render the readable ConfigError instead of raising. Update test_load_model_defaults_validation_statements, which previously asserted the raw TypeError, to expect the readable ConfigError. Regression from SQLMesh#4511. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
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.
Config validation errors located at a list or tuple index crash with an opaque
TypeErrorinstead of the intended readableConfigError._formatted_validation_errorsinsqlmesh/utils/pydantic.pybuilds the fieldlocation by joining pydantic's error
loctuple directly:Pydantic's
locmixes str field names with int sequence indices when an error isinside a list (for example
("items", 0, "x")), andstr.joinrejects the int:So any config error that resolves to a list element surfaces as a traceback rather
than the readable message the function exists to produce. A concrete user-facing
path is an invalid
model_defaults.pre_statementsentry, whoselocis("model_defaults", "pre_statements", 0, ...).The fix converts each
locpart tostrbefore joining:Nested-list config errors now render, for example,
Invalid field 'model_defaults.pre_statements.0...'as aConfigError.This is a regression from #4511, which replaced the earlier single-element
loc[0]access (never affected by int indices) with the".".join(loc)form.Test Plan
tests/utils/test_pydantic.py::test_validation_error_message_with_list_index_location:builds a real nested-model
ValidationError(loc == ("items", 0, "x")) andasserts
validation_error_messagereturns the formatted string instead ofraising. Verified it fails with the
TypeErrorbefore the fix and passes after.tests/core/test_config.py::test_load_model_defaults_validation_statements:it previously asserted the raw
TypeError, which codified the crash. It nowexpects the readable
ConfigError(Invalid field 'model_defaults.pre_statements.0...').Also verified this fails before the fix and passes after.
pytest tests/utils/test_pydantic.py tests/core/test_config.py -m "not slow and not docker":76 passed.
make style(ruff check + ruff format + mypy) clean on the changed files.Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCO