You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an Aggregate is loaded by the AggregateStore, if the aggregate has Snapshots configured, after initializing the Aggregate with the Snapshot data, the Aggregate version is not modified and remains in 0.
The eventhorizon.Snapshot structure contains the Version field, but it is not set in the Aggregate.
If the Aggregate contains more events (not included in the Snapshot), the application of this events will set the Version correctly, and the error is hidden.
To Reproduce
Steps to reproduce the behavior:
Create an Aggregate
Configure it to take a snapshot every 2 events
Send a command that fires 2 events in the aggregate
A Snapshot should be taken and persisted
Send another command that fires one event
The aggregate should be loaded from the Snapshot
The aggregate will have version 0 (it should be 2)
The new event will have version 1, instead of 3
The persistence of events will fail
Expected behavior
In step 6, when the aggregate is loaded from the Snapshot store, it should have Version 2
In step 8, the new event should have version 3, and it is correctly persisted
Screenshots
N/A
Additional context
Add any other context about the problem here.
func (r *AggregateStore) Load(ctx context.Context, aggregateType eh.AggregateType, id uuid.UUID) (eh.Aggregate, error) {
// ...
fromVersion := 1
if sa, ok := a.(eh.Snapshotable); ok && r.isSnapshotStore {
snapshot, err := r.snapshotStore.LoadSnapshot(ctx, id)
if err != nil {
return nil, &eh.AggregateStoreError{
Err: err,
Op: eh.AggregateStoreOpLoad,
AggregateType: aggregateType,
AggregateID: id,
}
}
if snapshot != nil {
sa.ApplySnapshot(snapshot)
fromVersion = snapshot.Version + 1
a.SetAggregateVersion(snapshot.Version) // <--- THIS IS THE MISSING LINE
}
}
// ...
The text was updated successfully, but these errors were encountered:
Describe the bug
When an Aggregate is loaded by the
AggregateStore
, if the aggregate has Snapshots configured, after initializing the Aggregate with the Snapshot data, the Aggregate version is not modified and remains in 0.The
eventhorizon.Snapshot
structure contains theVersion
field, but it is not set in the Aggregate.If the Aggregate contains more events (not included in the Snapshot), the application of this events will set the Version correctly, and the error is hidden.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
In step 6, when the aggregate is loaded from the Snapshot store, it should have Version 2
In step 8, the new event should have version 3, and it is correctly persisted
Screenshots
N/A
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: