Fix value type builder selection when a nullable sibling factory is present#4289
Merged
jeremydmiller merged 1 commit intoJasperFx:masterfrom Apr 26, 2026
Conversation
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.
Suggestion on a fix for issue #4288
Why
RegisterValueTypeselected the static builder method by parameter signature alone (FirstOrDefaultover publicstatic methods with one parameter matching the wrapped value type). When a Vogen value object had a nullable sibling
factory — e.g.
static T? FromNullable(string?)alongsidestatic T From(string)—FirstOrDefaultcould pick thenullable one. That builder's
ReturnTypeisNullable<T>, which then blew up insideValueTypeInfo.CreateWrapper,which assumes the builder returns
Titself. The symptom reported in #4288 was a crash when generating DDL for anycomputed index over the value type.
Changes
src/Marten/StoreOptions.Identity.cs—RegisterValueTypenow collects every candidate with the correct parametersignature and prefers the one whose
ReturnType == type, falling back to the first candidate. Preserves priorbehaviour for value types that expose only a single matching builder.
src/ValueTypeTests/Bugs/Bug_4288_value_type_with_nullable_factory.cs— regression test covering (1) DDL generationfor a computed index over the value type and (2) round-trip + query using
Bug4288Value, which exposesFromNullable.src/ValueTypeTests/registration.cs— new unit testpicks_builder_whose_return_type_matches_value_typethat pinsthe selection rule, plus a
SpecialValueWithNullableSiblingfixture (withFromandFromNullableside by side).Verification
dotnet build src/Marten/Marten.csproj— succeeds.dotnet test src/ValueTypeTests/ValueTypeTests.csproj—registration.picks_builder_whose_return_type_matches_value_type(pure unit test, no Postgres dependency) passes;Bug_4288_value_type_with_nullable_factory(
can_generate_ddl_for_index_over_value_type_with_nullable_sibling_factoryandcan_round_trip_and_query_value_type_with_nullable_sibling_factory) passes against a local Postgres; the existingregistrationsuite stays green.FirstOrDefault()fallback returnsthe same method the old code used to pick.