Repository navigation
Fix 2.1.86 unbox-gate regressions: array columns to interface members, sql_variant to primitives - #2271
Merged
Conversation
…, sql_variant to primitives The direct-unbox gate rewritten in 6d48ef6 broke two shapes that worked in 2.1.79: - array columns into interface members (IReadOnlyList<T> etc): the TypeCode tests excluded Object/Object pairs entirely, removing the runtime-checked castclass those relied on. The gate now admits reference-typed targets under that pairing, which also covers Npgsql 7/8/10 reporting array columns as typeof(Array) - a shape no static assignability test can prove (#2231) - sql_variant columns into primitive members: colType == typeof(object) was added to the direct-unbox branch, so a boxed Int32 into a bool member blind-unboxed and threw instead of coercing via flexible-convert. object columns now direct-unbox only into TypeCode.Object targets (Guid etc), where the runtime box is the only truth available (#2234) Value-type Object/Object pairs (TimeSpan vs TimeOnly?) stay on the flexible-convert path, preserving the DateOnly/TimeOnly fixes from #2228. Fixes #2231, fixes #2234
This was referenced Nov 20, 2026
This was referenced Nov 20, 2026
This was referenced Nov 30, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #2231, fixes #2234.
Both regressions trace to the direct-unbox gate rewritten in 6d48ef6 (#2228, shipped in 2.1.86):
dataTypeCode == unboxTypeCode && dataTypeCode != TypeCode.Objecttest excluded Object/Object pairs entirely, removing the runtime-checkedcastclassthat let array columns land in interface members (IReadOnlyList<short>etc). The gate now admits reference-typed targets under that pairing. Crucially, this also covers the shape where the provider'sGetFieldTypeis too weak to prove the match statically: Npgsql 7, 8 and 10 report array columns astypeof(Array)(only 9.0.0–9.0.4 report the concrete array type), so anIsAssignableFrom-style compile-time check cannot work there — only the runtimecastclasscan, which is what pre-2.1.86 emitted.colType == typeof(object)was added to the direct-unbox branch, so a sql_variant holding a boxedInt32read into aboolmember blind-unboxed and threwInvalidCastExceptioninstead of coercing via the flexible-convert path.objectcolumns now direct-unbox only intoTypeCode.Objecttargets (Guid,Guid?— where the runtime box is the only truth available, and keeping Re-enable DateOnly/TimeOnly support, fixing the defects that got it disabled #2228's fast path for those), and otherwise coerce. This also fixes the unreported sibling case of variantInt32→stringmember.Value-type Object/Object pairs (
TimeSpancolumn vsTimeOnly?member, say) stay on the flexible-convert path, so the DateOnly/TimeOnly fixes from #2228 are preserved — the new tests pin those guards too.Tests, all red on main and green here, run against real servers locally (docker Postgres + SQL Server 2019; full suite 794 passed / 0 failed on net8.0 and net10.0):
typeof(Array)shape that provider-typed tests can missSERVERPROPERTYrepro)smallint[]/int[]columns intoIReadOnlyList<short>/IEnumerable<int>/array members — these run under the Npgsql 10typeof(Array)shape in CICredit where due: this builds on the diagnosis and partial fixes in #2267 (@lqkhanh295 — closest to complete, but its
IsAssignableFromcheck cannot reach the Npgsql 7/8/10typeof(Array)shape), #2244 (@Arthur031221 — the cleanest sql_variant half), #2246 (@SENESO) and #2239/#2241 (@leandrommedeiros, @SENESO). Those PRs are superseded by this one.