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

Open

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.name → createdatutc
  • 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

Activity

  1. SophieLee-Hoareau commented on Feb 25, 2026

    @SophieLee-Hoareau
    Author

    model example (project dialects is t-sql, normalisation=case_insensitive)

    `MODEL (
    name analytics_usersessions.usersession_details,
    kind INCREMENTAL_BY_TIME_RANGE (
    time_column CreatedAtUtc
    ),
    tags 'usersessions',
    grain UserSessionId,
    cron '@daily',
    audits (
    NUMBER_OF_ROWS(threshold := 1),
    UNIQUE_VALUES(columns := (
    UserSessionId
    )),
    NOT_NULL(columns := (
    UserSessionId
    ))
    )
    );

    SELECT
    us.StartedAtUtc AS CreatedAtUtc,
    us.UserSessionId,
    us.UserId,
    us.OrganisationId,
    us.Device_Brand,
    us.Device_Family,
    us.Device_Model,
    COALESCE(SmartEnum_FormFactor.[Name], 'Unknown') AS Device_FormFactor,
    us.OS_Family,
    us.OS_Major,
    us.OS_Minor,
    us.Browser_Family,
    us.Browser_Major,
    us.Browser_Minor,
    us.Location_City AS IpLocation_City,
    us.Location_CountryCode AS IpLocation_CountryCode,
    us.Location_Latitude AS IpLocation_Latitude,
    us.Location_Longitude AS IpLocation_Longitude
    FROM orgs.UserSessions AS us
    WHERE
    us.StartedAtUtc BETWEEN @start_dt AND @end_dt
    LEFT JOIN [orgs].[SmartEnum_FormFactor] AS SmartEnum_FormFactor
    ON us.Device_FormFactor = SmartEnum_FormFactor.Id`

  2. changed the title [-]Using kind INCREMENTAL_BY_TIME_RANGE and running sqlmesh plan give 'ConfigError: Time column '' not found in model'[/-] [+]Using kind INCREMENTAL_BY_TIME_RANGE and running sqlmesh plan give 'ConfigError: Time column '' not found in model', snowflake normalisation= case_insensitive[/+] on Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions