Skip to content

fix(model): raise ConfigError for empty time_column tuple#5886

Open
anxkhn wants to merge 1 commit into
SQLMesh:mainfrom
anxkhn:patch-8
Open

fix(model): raise ConfigError for empty time_column tuple#5886
anxkhn wants to merge 1 commit into
SQLMesh:mainfrom
anxkhn:patch-8

Conversation

@anxkhn

@anxkhn anxkhn commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

A model declaring an empty time_column tuple, for example:

MODEL (
  name db.table,
  kind INCREMENTAL_BY_TIME_RANGE(time_column ())
);

parsed the value into an empty exp.Tuple, and TimeColumn.create
(sqlmesh/core/model/kind.py) indexed v.expressions[0] without first checking
whether the tuple was empty. That raised a bare IndexError: list index out of range with no configuration context, instead of the ConfigError that the same
method already raises for the other empty or invalid time_column inputs
(ConfigError("Time Column cannot be empty.") in _column_validator, and
ConfigError(f"Invalid time_column: '{v}'.") in the create fallthrough).

This adds a guard at the top of the isinstance(v, exp.Tuple) branch that raises
the same "Time Column cannot be empty." ConfigError, so the empty-tuple case
is reported the same way as the other invalid inputs. ConfigError was already
imported; no behavior changes for any valid time_column.

Test Plan

  • Added a regression case to test_time_column in tests/core/test_model.py
    that loads a model with time_column () and asserts it raises
    ConfigError matching "Time Column cannot be empty.".
  • Confirmed the test is red before the fix (it fails with IndexError at the
    old v.expressions[0] line) and green after.
  • make style clean 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

  • 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

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>
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.

1 participant