You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(model): fall back to case-insensitive time column lookup in convert_to_time_column - #6221
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.
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.
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: 4
Check name
Status
Explanation
Title check
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
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
[#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
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.
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.
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
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.
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
Verification
Summary by CodeRabbit