fix(model): raise ConfigError for empty time_column tuple#5886
Open
anxkhn wants to merge 1 commit into
Open
Conversation
An empty time_column tuple, e.g. `INCREMENTAL_BY_TIME_RANGE (time_column ())`, parsed into an empty exp.Tuple and TimeColumn.create indexed v.expressions[0] without checking, so it surfaced a bare IndexError with no config context instead of the ConfigError already used for the other empty/invalid time_column inputs. Guard the empty tuple and raise the same "Time Column cannot be empty." ConfigError. 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.
A model declaring an empty
time_columntuple, for example:parsed the value into an empty
exp.Tuple, andTimeColumn.create(
sqlmesh/core/model/kind.py) indexedv.expressions[0]without first checkingwhether the tuple was empty. That raised a bare
IndexError: list index out of rangewith no configuration context, instead of theConfigErrorthat the samemethod already raises for the other empty or invalid
time_columninputs(
ConfigError("Time Column cannot be empty.")in_column_validator, andConfigError(f"Invalid time_column: '{v}'.")in thecreatefallthrough).This adds a guard at the top of the
isinstance(v, exp.Tuple)branch that raisesthe same
"Time Column cannot be empty."ConfigError, so the empty-tuple caseis reported the same way as the other invalid inputs.
ConfigErrorwas alreadyimported; no behavior changes for any valid
time_column.Test Plan
test_time_columnintests/core/test_model.pythat loads a model with
time_column ()and asserts it raisesConfigErrormatching"Time Column cannot be empty.".IndexErrorat theold
v.expressions[0]line) and green after.make styleclean on the changed files (ruff check,ruff format,mypy).pytest tests/core/test_model.py -k "time_column or model_kind or incremental_by_time" -m "not slow and not docker"-> 16 passed.
Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCO