fix(types): handle connector >=4.3.0 interval year-month display format#4215
Merged
Conversation
snowflake-connector-python v4.3.0 changed the string representation of INTERVAL YEAR and INTERVAL MONTH values. When months=0, the connector now returns '+N' (just years) instead of '+N-0' (compound year-month). format_year_month_interval_for_display previously only treated a simple '+N' value as years when the type was exactly INTERVAL YEAR (start=YEAR, end=YEAR). For INTERVAL YEAR TO MONTH (start=YEAR, end=MONTH), it incorrectly treated '+N' as months, producing e.g. "INTERVAL '0-4'" instead of the correct "INTERVAL '4-0'" for 4 years. Fix: when start_field is YEAR, always interpret a simple '+N' value as years regardless of end_field. This is correct for both old connector (which always uses compound '+Y-M' format, so this branch is never hit) and new connector >=4.3.0 (which uses '+N' when the months component is zero). Co-authored-by: Cursor <cursoragent@cursor.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4215 +/- ##
=======================================
Coverage 95.04% 95.04%
=======================================
Files 171 171
Lines 43877 43877
Branches 7525 7525
=======================================
+ Hits 41703 41704 +1
Misses 1368 1368
+ Partials 806 805 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
sfc-gh-mayliu
approved these changes
May 11, 2026
Collaborator
sfc-gh-mayliu
left a comment
There was a problem hiding this comment.
LGTM. Can you update changelog.md for this bugfix? Please merge main to get the test infra fix for a required check
| ) | ||
|
|
||
|
|
||
| class TestFormatYearMonthIntervalForDisplay: |
Collaborator
There was a problem hiding this comment.
nint: can we make the test follow the existing style in this suite?
sfc-gh-yuwang
approved these changes
May 11, 2026
Collaborator
sfc-gh-yuwang
left a comment
There was a problem hiding this comment.
Approved with a nint, please take a look before merge, thanks!
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Fixes incorrect display of YEAR TO MONTH interval values when using
snowflake-connector-python>=4.3.0.Root Cause
snowflake-connector-pythonv4.3.0 changed the string representation of INTERVAL YEAR and INTERVAL MONTH types (see connector changelog: "Fix string representation of INTERVAL YEAR and INTERVAL MONTH types").Previously, the connector always returned compound year-month format (e.g.,
+4-0for 4 years, 0 months). Starting with v4.3.0, when the months component is zero, the connector returns just+4(omitting the-0suffix).format_year_month_interval_for_displayintype_utils.pyonly interpreted a simple+Nvalue as years when the type was exactlyINTERVAL YEAR(start_field=YEAR, end_field=YEAR). ForINTERVAL YEAR TO MONTH(start_field=YEAR, end_field=MONTH), the simple+Nvalue was incorrectly treated as months, producing:instead of:
Fix
When
start_fieldisYEAR, always interpret a simple+Nvalue (no dash) as years, regardless ofend_field. This is correct for:+Y-M, so the simple-value branch is never reached for YEAR TO MONTH types — no behavioral change.+Nwhen months=0 — now correctly interpreted as years.Reproduction
This was discovered via Snowpark Connect (SCOS) CI where
try_multiply(4, INTERVAL '1' YEAR)produced incorrect output after widening the connector version cap to<5.0.0.Test plan
tests/unit/test_datatype_mapper.pytests passMade with Cursor