Skip to content

Using kind INCREMENTAL_BY_TIME_RANGE and running sqlmesh plan give 'ConfigError: Time column '' not found in model', snowflake normalisation= case_insensitive #5710

@SophieLee-Hoareau

Description

@SophieLee-Hoareau

SQLMesh Bug Report

Title: INCREMENTAL_BY_TIME_RANGE: Time column not found when using normalization_strategy=case_insensitive with Snowflake

Repo: https://github.com/TobikoData/sqlmesh/issues


Bug Description

When using INCREMENTAL_BY_TIME_RANGE models with a Snowflake connection and normalization_strategy=case_insensitive in the dialect, sqlmesh plan fails with:

ConfigError: Time column '' not found in model 'my_schema.my_model'

Root Cause

In sqlmesh/core/model/definition.py, the convert_to_time_column method (line ~831) does a case-sensitive Python dict lookup:

if self.time_column.column.name not in columns_to_types:
  • normalization_strategy=case_insensitive lowercases the model's time_column.column.namecreatedatutc
  • engine_adapter.columns() returns Snowflake's native UPPERCASE column names → CREATEDATUTC
  • The case-sensitive not in check always fails

Reproduction

config.yaml:

gateways:
  snowflake_prod:
    model_defaults:
      dialect: "tsql,normalization_strategy=case_insensitive"
    connection:
      type: snowflake
      # ...

model.sql:

MODEL (
    name my_schema.my_model,
    kind INCREMENTAL_BY_TIME_RANGE (
        time_column CreatedAtUtc
    )
);

SELECT
    src.CreatedAtUtc,
    src.Id
FROM upstream.source AS src
WHERE src.CreatedAtUtc BETWEEN @start_date AND @end_date

Run sqlmesh --gateway snowflake_prod plan → fails with Time column '' not found.

Suggested Fix

Normalize the column names from engine_adapter.columns() before comparison, or make the lookup in convert_to_time_column case-insensitive:

# Before
if self.time_column.column.name not in columns_to_types:

# After
columns_to_types_lower = {k.lower(): v for k, v in columns_to_types.items()}
if self.time_column.column.name.lower() not in columns_to_types_lower:

A more robust fix might normalize column names at the point they're returned from engine_adapter.columns() (line ~501) to match the model's normalization strategy.

Environment

  • SQLMesh version: 0.230.1
  • Python: 3.12
  • Connection: Snowflake
  • Dialect: tsql,normalization_strategy=case_insensitive

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions