Skip to content

fix(#4966): update natural key on projection rebuild (JasperFx 2.28.1)#4970

Merged
jeremydmiller merged 1 commit into
masterfrom
bugs/4966-natural-key-update
Jul 17, 2026
Merged

fix(#4966): update natural key on projection rebuild (JasperFx 2.28.1)#4970
jeremydmiller merged 1 commit into
masterfrom
bugs/4966-natural-key-update

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Problem

A snapshot with a natural key that changes across events is not updated: the natural key is recorded once (from the create event) but never again when a later event changes it. FetchLatest-by-natural-key then can't find the stream under its new key — observed after a projection rebuild in #4966, but the same gap exists on live inline append.

Root cause & fix (JasperFx)

The natural-key lookup table mt_natural_key_X is maintained from NaturalKeyEventMappings discovered off the aggregate's [NaturalKeySource] methods. JasperFx's discovery silently skipped a two-arg static evolve method

[NaturalKeySource] public static Product Apply(ProductCodeChanged e, Product current)
    => current with { Code = new ProductCode(e.NewProductCode) };

— because the extractor builder only knew how to invoke a one-arg static factory; the two-arg call threw while composing and was swallowed. So the update event got no mapping and its key was never upserted.

Fixed in jasperfx#528 (extractor now binds one argument per parameter: event data → the event param, a fresh default aggregate → the TDoc param), released as JasperFx 2.28.1. This PR bumps the JasperFx packages to 2.28.1.

Test

Includes the original reproduction from #4967 — thanks @ytqsl (retained as co-author). It fails on 2.28.0 (should not be null but was) and passes on 2.28.1, verified locally against the published package.


Supersedes #4967. Closes #4966.

🤖 Generated with Claude Code

A natural key that CHANGES via an update event was never written to the
mt_natural_key_X lookup table — only the create event's key was recorded — so
FetchLatest-by-natural-key could not find the stream under its new key after a
rebuild (or live inline append). Root cause and fix are in JasperFx: natural-key
discovery silently skipped a two-arg static evolve method
(static TDoc Apply(TEvent e, TDoc current)), so no mapping was built for the
update event (#528). This bumps the JasperFx packages to 2.28.1 to pick
up that fix.

Includes the original reproduction test from #4967 (thanks @ytqsl); it fails on
2.28.0 ("should not be null but was") and passes on 2.28.1.

Supersedes #4967.
Closes #4966.

Co-Authored-By: Yossi Tamari <yossi.tamari@gov.ab.ca>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XKKBPsFJ83jd2o4hyGJnj6
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.

Natural key is not updated when rebuilding a projection

1 participant