Skip to content

fix: return interface{} scanType for sql_variant instead of nil#362

Merged
dlevy-msft-sql merged 1 commit into
microsoft:mainfrom
dlevy-msft-sql:fix/sql-variant-scantype
Apr 20, 2026
Merged

fix: return interface{} scanType for sql_variant instead of nil#362
dlevy-msft-sql merged 1 commit into
microsoft:mainfrom
dlevy-msft-sql:fix/sql-variant-scantype

Conversation

@dlevy-msft-sql
Copy link
Copy Markdown

Summary

sql_variant columns returned nil from ColumnType.ScanType(), which broke downstream libraries (e.g. Grafana - see grafana/grafana#81935) that rely on a non-nil reflect.Type for all column types.

Changes

  • makeGoLangScanType() now returns reflect.TypeOf((*interface{})(nil)).Elem() for typeVariant instead of reflect.TypeOf(nil)
  • Updated unit test to match

Since sql_variant can hold any SQL Server type (int, varchar, datetime, etc.), interface{} is the correct Go scan type representing its polymorphic nature.

Attribution

Thanks to @aangelisc for reporting this issue and identifying the root cause.

Fixes #186

sql_variant columns returned nil from ColumnType.ScanType(), which
broke downstream libraries (e.g. Grafana) that rely on a non-nil
reflect.Type for all column types.

Since sql_variant can hold any SQL Server type, return reflect.Type
for interface{} which correctly represents the polymorphic nature
of the type.

Fixes microsoft#186
@dlevy-msft-sql dlevy-msft-sql force-pushed the fix/sql-variant-scantype branch from e98b256 to 9fb2eee Compare April 17, 2026 21:04
@dlevy-msft-sql dlevy-msft-sql added this to the v1.11.0 milestone Apr 17, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.58%. Comparing base (455b2b2) to head (9fb2eee).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main     #362       +/-   ##
===========================================
+ Coverage   80.00%   96.58%   +16.57%     
===========================================
  Files          34       91       +57     
  Lines        6653    74078    +67425     
===========================================
+ Hits         5323    71551    +66228     
- Misses       1061     2190     +1129     
- Partials      269      337       +68     
Flag Coverage Δ
unittests 96.52% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
types.go 82.08% <100.00%> (ø)

... and 59 files with indirect coverage changes

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

@dlevy-msft-sql dlevy-msft-sql merged commit 296a83a into microsoft:main Apr 20, 2026
7 checks passed
@dlevy-msft-sql dlevy-msft-sql deleted the fix/sql-variant-scantype branch April 20, 2026 14:52
@dlevy-msft-sql dlevy-msft-sql modified the milestones: v1.11.0, v1.10.0 Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql_variant invalid scanType value

3 participants