Skip to content

fix(types): handle connector >=4.3.0 interval year-month display format#4215

Merged
sfc-gh-joshi merged 3 commits into
mainfrom
kgadomski/fix-interval-year-month-display
May 12, 2026
Merged

fix(types): handle connector >=4.3.0 interval year-month display format#4215
sfc-gh-joshi merged 3 commits into
mainfrom
kgadomski/fix-interval-year-month-display

Conversation

@sfc-gh-kgadomski
Copy link
Copy Markdown
Contributor

Summary

Fixes incorrect display of YEAR TO MONTH interval values when using snowflake-connector-python>=4.3.0.

Root Cause

snowflake-connector-python v4.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-0 for 4 years, 0 months). Starting with v4.3.0, when the months component is zero, the connector returns just +4 (omitting the -0 suffix).

format_year_month_interval_for_display in type_utils.py only interpreted a simple +N value as years when the type was exactly INTERVAL YEAR (start_field=YEAR, end_field=YEAR). For INTERVAL YEAR TO MONTH (start_field=YEAR, end_field=MONTH), the simple +N value was incorrectly treated as months, producing:

INTERVAL '0-4' YEAR TO MONTH   (wrong: 0 years, 4 months)

instead of:

INTERVAL '4-0' YEAR TO MONTH   (correct: 4 years, 0 months)

Fix

When start_field is YEAR, always interpret a simple +N value (no dash) as years, regardless of end_field. This is correct for:

  • Old connector (<4.3.0): always uses compound format +Y-M, so the simple-value branch is never reached for YEAR TO MONTH types — no behavioral change.
  • New connector (>=4.3.0): uses +N when months=0 — now correctly interpreted as years.

Reproduction

from snowflake.snowpark._internal.type_utils import format_year_month_interval_for_display
from snowflake.snowpark.types import YearMonthIntervalType

# Bug: '+4' with YEAR TO MONTH type treated as 4 months instead of 4 years
result = format_year_month_interval_for_display('+4', YearMonthIntervalType.YEAR, YearMonthIntervalType.MONTH)
# Before: "INTERVAL '0-4' YEAR TO MONTH" (wrong)
# After:  "INTERVAL '4-0' YEAR TO MONTH" (correct)

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

  • Added parametrized unit tests covering both old compound format and new simple format for all interval subtypes (YEAR, MONTH, YEAR TO MONTH)
  • All existing tests/unit/test_datatype_mapper.py tests pass

Made with Cursor

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-commenter
Copy link
Copy Markdown

codecov-commenter commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.04%. Comparing base (d4e00e4) to head (bfcac42).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@sfc-gh-mayliu sfc-gh-mayliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can you update changelog.md for this bugfix? Please merge main to get the test infra fix for a required check

Comment thread tests/unit/test_datatype_mapper.py Outdated
)


class TestFormatYearMonthIntervalForDisplay:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nint: can we make the test follow the existing style in this suite?

Copy link
Copy Markdown
Collaborator

@sfc-gh-yuwang sfc-gh-yuwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with a nint, please take a look before merge, thanks!

@sfc-gh-joshi sfc-gh-joshi merged commit 0537409 into main May 12, 2026
24 of 30 checks passed
@sfc-gh-joshi sfc-gh-joshi deleted the kgadomski/fix-interval-year-month-display branch May 12, 2026 16:58
@github-actions github-actions Bot locked and limited conversation to collaborators May 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants