Skip to content

fix(model): fall back to case-insensitive time column lookup in convert_to_time_column - #6221

Open
boomesh11 wants to merge 1 commit into
SQLMesh:mainfrom
boomesh11:fix/time-column-case-insensitive-lookup
Open

boomesh11 wants to merge 1 commit into
SQLMesh:mainfrom
boomesh11:fix/time-column-case-insensitive-lookup

Conversation

@boomesh11

@boomesh11 boomesh11 commented Nov 16, 2026 •

Copy link
Copy Markdown

Fixes #5710.

Problem

In convert_to_time_column() (sqlmesh/core/model/definition.py), looking up self.time_column.column.name in columns_to_types was strictly case-sensitive. When a model uses
ormalization_strategy=case_insensitive (lowercasing ime_column.column.name) against a warehouse such as Snowflake that returns uppercase column names from engine_adapter.columns(), convert_to_time_column() raised ConfigError: Time column '...' not found in model '...'.

Fix

  • Try exact lookup columns_to_types.get(time_column_name) first, and fall back to case-insensitive matching against columns_to_types before raising ConfigError.

Verification

  • Added ests/core/test_time_column_case_insensitive.py.
  • Ran pytest -o addopts="" --noconftest tests/core/test_time_column_case_insensitive.py: 1 passed.

Summary by CodeRabbit

  • Bug Fixes
    • Time-column type matching now handles differences in capitalization, improving compatibility when column names use inconsistent casing.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The time-column type lookup now falls back to a case-insensitive column-name match when an exact match is unavailable. A test checks the lookup with differently cased names.

Changes: Time-column lookup

Layer / File(s) Summary
Resolve and test time-column type
sqlmesh/core/model/definition.py, tests/core/test_time_column_case_insensitive.py
The lookup checks for an exact column-name match, then checks names without case sensitivity. The test verifies that differently cased names produce an exp.Expr.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: mday-io

Merge Risk: Minimal · up to bf3c0

This change makes time-column lookup tolerate case differences between model and warehouse column names, which addresses the reported failure. Existing exact-match behavior is preserved, so the merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: convert_to_time_column() now falls back to a case-insensitive time column lookup. The raw summary confirms the exact-match-first, then case-insensitive, behavior in sq…
Description check Passed The description covers the problem, the fix, and verification, which are the substance of the template's Description and Test Plan sections. It links issue #5710 and names the new test file and the py…
Linked Issues check Passed [#5710] The issue requires that INCREMENTAL_BY_TIME_RANGE models with normalization_strategy=case_insensitive on Snowflake stop failing with "Time column ... not found" when the warehouse returns uppe…
Out of Scope Changes check Passed The whole-PR diff against the merge base touches two files. sqlmesh/core/model/definition.py changes only convert_to_time_column, which is the function named in issue #5710. The change adds an exact-m…
Full details: Title check

Explanation

The title names the main change: convert_to_time_column() now falls back to a case-insensitive time column lookup. The raw summary confirms the exact-match-first, then case-insensitive, behavior in sqlmesh/core/model/definition.py, and the linked issue #5710 covers the same Snowflake case-mismatch problem. The title is 86 characters, which is slightly long but within normal limits.

Full details: Description check

Explanation

The description covers the problem, the fix, and verification, which are the substance of the template's Description and Test Plan sections. It links issue #5710 and names the new test file and the pytest command with its result. The template's Checklist section is missing: it does not show whether make style was run, whether all existing tests pass (make fast-test), or whether commits are signed off (git commit -s). The description also has broken text in the Problem section, where some characters are missing or replaced (for example 'ormalization_strategy' and 'ime_column'). Those are likely escape-sequence artifacts from the source text.

Resolution

Optionally add the template's Checklist section, with the status of make style, make fast-test, and DCO sign-off. Also correct the corrupted characters in the Problem section (for example 'ormalization_strategy', 'ime_column', and 'ests/core/...'), so the file paths and parameter names read correctly.

Full details: Linked Issues check

Explanation

[#5710] The issue requires that INCREMENTAL_BY_TIME_RANGE models with normalization_strategy=case_insensitive on Snowflake stop failing with "Time column ... not found" when the warehouse returns uppercase column names. The root cause is the case-sensitive lookup in _Model.convert_to_time_column. At the reviewed head, sqlmesh/core/model/definition.py first tries an exact lookup with columns_to_types.get(time_column_name). If that returns None, it retries with a lowercased key map of columns_to_types, using time_column_name.lower(). It raises ConfigError only when both lookups fail. This resolves the reported mismatch between the lowercased model column name and the uppercase warehouse name. The added test tests/core/test_time_column_case_insensitive.py loads a T-SQL model with case_insensitive normalization and passes columns_to_types with uppercase keys (CREATEDATUTC), which exercises the fallback path. The test asserts only that the result is an exp.Expr. It does not check the returned value. The end-to-end sqlmesh plan path was not executed. The code path is evidenced by the diff and the test.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base touches two files. sqlmesh/core/model/definition.py changes only convert_to_time_column, which is the function named in issue #5710. The change adds an exact-match lookup and a case-insensitive fallback, and keeps the existing ConfigError. tests/core/test_time_column_case_insensitive.py covers this behavior. No unrelated changes were found in the reviewed diff.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fcd5d0f0-8d71-4049-af80-589f82a303f2
Commits

Reviewing files that changed from the base of the PR and between 3df452c and bf3c0a3.

Files selected for processing: 2

  • sqlmesh/core/model/definition.py
  • tests/core/test_time_column_case_insensitive.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant