Fix NaturalKeySource discovery when methods are on the projection class#4240
Merged
Merged
Conversation
When [NaturalKeySource] methods are on the projection class (e.g., SingleStreamProjection<TDoc, TId>) rather than the aggregate, natural key discovery now finds them. Previously FetchLatest/FetchForWriting with natural keys returned null in this case. - Upgrade JasperFx.Events to 1.26.1 (contains the discovery fix) - Bump Marten to 8.29.1 - New test: BookListing aggregate with Isbn natural key where all [NaturalKeySource] methods are on the projection class - 29/29 natural key tests passing, zero regressions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cc84c80 to
f9a80fc
Compare
This was referenced Apr 14, 2026
This was referenced Apr 27, 2026
This was referenced May 11, 2026
This was referenced May 14, 2026
This was referenced May 25, 2026
This was referenced Jun 8, 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.
Summary
When
[NaturalKeySource]methods are defined on the projection class (e.g.,SingleStreamProjection<TDoc, TId>) rather than the aggregate type itself, the natural key discovery failed to find them. This causedFetchLatestandFetchForWritingwith natural keys to return null.Root Cause
discoverNaturalKey()only searched the aggregate type (typeof(TDoc)) for[NaturalKeySource]methods. When Create/Apply methods with the attribute were on the projection class, theEventMappingslist remained empty and theNaturalKeyProjectionnever populated the lookup table.Fix (in JasperFx.Events)
discoverNaturalKey()now also searchesGetType()(the projection class) for[NaturalKeySource]methodsIEvent.StreamKey)Test
New test
natural_key_source_on_projection_class_with_string_streamswithBookListingaggregate +Isbnnatural key where all[NaturalKeySource]methods are on the projection class.Depends on JasperFx/jasperfx@b5aba64 (pushed to main)
Test plan
🤖 Generated with Claude Code