Skip to content

fix: read a filter value into a nullable property instead of throwing - #27

Merged
RicardoZambon merged 1 commit into
mainfrom
fix/nullable-filter-values
Sep 16, 2026
Merged

RicardoZambon merged 1 commit into
mainfrom
fix/nullable-filter-values

Conversation

@RicardoZambon

Copy link
Copy Markdown
Owner

Filtering by any nullable property failed before a row was read:

InvalidCastException: Invalid cast from 'System.String' to
'System.Nullable`1[[System.Int64, ...]]'

GetFilterValue switches on Type.GetTypeCode(resultType), and that answers Object for Nullable rather than Int64, so every nullable type fell through to the default branch and Convert.ChangeType -- which cannot produce a Nullable at all. IsEnum is false for Nullable for the same reason, so nullable enums went the same way.

Nullable.GetUnderlyingType unwraps it once, at the top, and the rest of the method reasons about the underlying type. Returning the underlying value boxed is what callers already expect: RunFilter converts the constant to the member's own type, which is how a non-nullable enum has always arrived as its Int32.

Measured against 1.13.2 with the payload that reported it, long?, int?, bool?, decimal?, double?, DateTime? and nullable enums every one threw; all of them now return the value, from a JSON number and from a JSON string alike. The non-nullable cases and string are byte for byte what they were.

Filtering by any nullable property failed before a row was read:

  InvalidCastException: Invalid cast from 'System.String' to
  'System.Nullable`1[[System.Int64, ...]]'

GetFilterValue switches on Type.GetTypeCode(resultType), and that answers Object
for Nullable<long> rather than Int64, so every nullable type fell through to the
default branch and Convert.ChangeType -- which cannot produce a Nullable<T> at
all. IsEnum is false for Nullable<TEnum> for the same reason, so nullable enums
went the same way.

Nullable.GetUnderlyingType unwraps it once, at the top, and the rest of the
method reasons about the underlying type. Returning the underlying value boxed is
what callers already expect: RunFilter converts the constant to the member's own
type, which is how a non-nullable enum has always arrived as its Int32.

Measured against 1.13.2 with the payload that reported it, long?, int?, bool?,
decimal?, double?, DateTime? and nullable enums every one threw; all of them now
return the value, from a JSON number and from a JSON string alike. The
non-nullable cases and string are byte for byte what they were.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@RicardoZambon RicardoZambon self-assigned this Sep 16, 2026
@RicardoZambon
RicardoZambon merged commit d98407c into main Sep 16, 2026
6 checks passed
@RicardoZambon
RicardoZambon deleted the fix/nullable-filter-values branch September 16, 2026 12:47
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.13.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant