Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NonExistentStreamException when appending to existing stream with UseMandatoryStreamTypeDeclaration #3518

Closed
I4QvViGzUN0F opened this issue Oct 28, 2024 · 2 comments

Comments

@I4QvViGzUN0F
Copy link

Following on from #3482.

I upgraded to version 7.31.0 and am using UseMandatoryStreamTypeDeclaration=true. When I try to append events to an existing stream a NonExistentStreamException is thrown inside Marten.Events.Operations.QuickAppendEventsOperationBase.PostprocessAsync()

Marten.Exceptions.NonExistentStreamException: Attempt to append to a nonexistent event stream '31b1d9a6-0675-4d6b-b4b4-99d65caab067'
   at Marten.Events.Operations.QuickAppendEventsOperationBase.PostprocessAsync(DbDataReader reader, IList`1 exceptions, CancellationToken token)
   at Marten.Internal.Sessions.OperationPage.ApplyCallbacksAsync(DbDataReader reader, IList`1 exceptions, CancellationToken token)
   at Marten.Internal.Sessions.AutoClosingLifetime.ExecuteBatchPagesAsync(IReadOnlyList`1 pages, List`1 exceptions, CancellationToken token)
   at Marten.Internal.Sessions.AutoClosingLifetime.ExecuteBatchPagesAsync(IReadOnlyList`1 pages, List`1 exceptions, CancellationToken token)
   at JasperFx.Core.Exceptions.ExceptionTransformExtensions.TransformAndThrow(IEnumerable`1 transforms, Exception ex)
   at Marten.Internal.Sessions.AutoClosingLifetime.ExecuteBatchPagesAsync(IReadOnlyList`1 pages, List`1 exceptions, CancellationToken token)
   at Marten.Internal.Sessions.AutoClosingLifetime.ExecuteBatchPagesAsync(IReadOnlyList`1 pages, List`1 exceptions, CancellationToken token)
   at Marten.Internal.Sessions.AutoClosingLifetime.ExecuteBatchPagesAsync(IReadOnlyList`1 pages, List`1 exceptions, CancellationToken token)
   at Polly.ResiliencePipeline.<>c__2`1.<<ExecuteAsync>b__2_0>d.MoveNext()
--- End of stack trace from previous location ---
   at Polly.Outcome`1.GetResultOrRethrow()
   at Polly.ResiliencePipeline.ExecuteAsync[TState](Func`3 callback, TState state, CancellationToken cancellationToken)
   at Marten.Internal.Sessions.DocumentSessionBase.ExecuteBatchAsync(IUpdateBatch batch, CancellationToken token)
   at JasperFx.Core.Exceptions.ExceptionTransformExtensions.TransformAndThrow(IEnumerable`1 transforms, Exception ex)
   at Marten.Internal.Sessions.DocumentSessionBase.ExecuteBatchAsync(IUpdateBatch batch, CancellationToken token)
   at Marten.Internal.Sessions.DocumentSessionBase.ExecuteBatchAsync(IUpdateBatch batch, CancellationToken token)
   at Marten.Internal.Sessions.DocumentSessionBase.SaveChangesAsync(CancellationToken token)
   at AllInOne.Common.EventStorage.Marten.Infrastructure.Repositories.MartenAggregateRepository.AppendEventToAggregateStreamAsync[TAggregate](EventContainer eventContainer, CancellationToken cancellationToken)

Confirmation that the stream exists with 1 creation event

image

Append code (I confirmed that the tenant_id is correct).

public async Task AppendEventToAggregateStreamAsync<TAggregate>(
    EventContainer eventContainer,
    CancellationToken cancellationToken)
    where TAggregate : class, IAggregate
{
    await using var session = store.LightweightSession(tenantId: eventContainer.Site.ToString());

    session.SetMetaData(eventContainer.Trace, eventContainer.Audit);

    session.Events.Append(eventContainer.AggregateId, eventContainer.Event);

    await session.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

    log.LogInformation(
        "Stream Id {streamId} - Appended event of type {eventType}",
        eventContainer.AggregateId,
        eventContainer.Event.GetType().Name);
}

This is the location that the exception is being thrown. Marten.Events.Operations.QuickAppendEventsOperationBase.PostprocessAsync()

image

@jeremydmiller
Copy link
Member

You're from Arcadis? This is the strategy where you're fitting Marten within what had been EventStoreDb usage? I wouldn't recommend your MartenAggregateRepository wrapper in normal usage

@I4QvViGzUN0F
Copy link
Author

Yes, this is Chris from Arcadis. Sorry for the gibberish username!

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

No branches or pull requests

2 participants