-
-
Notifications
You must be signed in to change notification settings - Fork 81
Description
Hello everybody! Thanks a lot for such a good library, we use it extensively with minimal issues. However recently I encountered a situation when Eventuous behavior looks like a bug.
Describe the bug
Sometimes I need an aggregate to use a stream with events starting not from 0. In this case only the first command will succeed, all the subsequent one will fail cause Aggregate.OriginalVersion
always start from zero.
Use case: I have an aggregate user onboarding
with id UserOnboarding-123
matched to user id User-123
for easier association and location in EventStore.
During development we shipped not backward-compatible source code (our mistake) and decided to delete the
UserOnboarding-123
stream and execute commands via API to put it into valid state.
The first command (create) was executed properly, but all other commands failed (like mark onboarding step as done).
So now I'm forced to more manual options:
- Use new stream id and spend time on application redesign, also lose readability and make app support harder
- Update metadata manually in EventStore and restore the whole stream, ship code that can support it.
In my opinion it will be neat to continue using aggregate as-is and leave the stream starting from non-zero value
To Reproduce
Steps to reproduce the behavior:
- create an aggregate via command service
- issue a "create" command to it
- delete aggregate stream via
EventStoreClient.DeleteAsync
- issue a new "create" command to aggregate -> it will work
- issue a new state change command to aggregate -> it will not work
Expected behavior
All commands can be executed by aggregate as usual
Screenshots
Exception
Eventuous.OptimisticConcurrencyException`2[illumi.UsersOnboarding.Domain.UserOnboarding,illumi.UsersOnboarding.Domain.UserOnboardingState]: Update of UserOnboarding failed due to the wrong version in stream UserOnboarding-669Z06GT32leMzbw3kwO6D ---> Eventuous.AppendToStreamException: Unable to append events to UserOnboarding-669Z06GT32leMzbw3kwO6D: Append failed due to WrongExpectedVersion. Stream: UserOnboarding-669Z06GT32leMzbw3kwO6D, Expected version: 1, Actual version: 2 ---> EventStore.Client.WrongExpectedVersionException: Append failed due to WrongExpectedVersion. Stream: UserOnboarding-669Z06GT32leMzbw3kwO6D, Expected version: 1, Actual version: 2 at EventStore.Client.WriteResultExtensions.OptionallyThrowWrongExpectedVersionException(IWriteResult writeResult, EventStoreClientOperationOptions options) at EventStore.Client.EventStoreClient.AppendToStreamAsync(String streamName, StreamRevision expectedRevision, IEnumerable`1 eventData, Action`1 configureOperationOptions, Nullable`1 deadline, UserCredentials userCredentials, CancellationToken cancellationToken) at Eventuous.EventStore.EsdbEventStore.<>c__DisplayClass7_0.<b__2>d.MoveNext() --- End of stack trace from previous location --- at Eventuous.EventStore.EsdbEventStore.TryExecute[T](Func`1 func, String stream, Func`1 getError, Func`3 getException) --- End of inner exception stack trace --- at Eventuous.EventStore.EsdbEventStore.TryExecute[T](Func`1 func, String stream, Func`1 getError, Func`3 getException) at Eventuous.Diagnostics.Tracing.TracedEventWriter.AppendEvents(StreamName stream, ExpectedStreamVersion expectedVersion, IReadOnlyCollection`1 events, CancellationToken cancellationToken) at Eventuous.StoreFunctions.Store(IEventWriter eventWriter, StreamName streamName, ExpectedStreamVersion expectedStreamVersion, IReadOnlyCollection`1 changes, AmendEvent amendEvent, CancellationToken cancellationToken) --- End of inner exception stack trace --- at illumi.Infrastructure.Commanding.CommandExecutorExtensions.Execute[TCommand,TState](ICommandExecutor`1 commandService, TCommand cmd, CancellationToken ct, String correlationId) in /Users/andrey/Programming/illumi/illumi-backend/illumi.Infrastructure/Commanding/ICommandService.cs:line 23 at illumi.UsersOnboarding.Api.UserOnboardingMutation.CompleteStep(OnboardingStep step, UserId userId, ICommandExecutor`1 commandService, CancellationToken ct) in /Users/andrey/Programming/illumi/illumi-backend/illumi.UsersOnboarding/Api/UserOnboardingMutation.cs:line 28 at HotChocolate.Resolvers.Expressions.ExpressionHelper.AwaitTaskHelper[T](Task`1 task) at HotChocolate.Types.Helpers.FieldMiddlewareCompiler.<>c__DisplayClass9_0.<b__0>d.MoveNext() --- End of stack trace from previous location --- at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken) at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)Line that causes the exception
Additional context
Add any other context about the problem here.