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

UpdateRevision with SaveChangesAsync generates a ConcurrencyException #3284

Closed
ivanoterrivel2 opened this issue Jun 26, 2024 · 0 comments
Closed

Comments

@ivanoterrivel2
Copy link

I want to use SaveChangesAsync after calling the UpdateRevision method.

On Marten solution, in numeric_revisioning.cs test files, for the public async Task optimistic_concurrency_failure_with_update_revision()
If I change the SaveChanges() to use SaveChangesAsync() it throws a Marten.Exceptions.ConcurrencyException.
The tests with UpdateRevision seem to fail when used with SaveChangesAsync();

[Fact]
public async Task optimistic_concurrency_failure_with_update_revision()
{
    var doc1 = new RevisionedDoc { Name = "Tim" };
    theSession.Store(doc1);
    theSession.SaveChanges();

    doc1.Name = "Bill";
    theSession.Store(doc1);
    theSession.SaveChanges();

    doc1.Name = "Dru";
    theSession.Store(doc1);
    theSession.SaveChanges();

    var doc2 = new RevisionedDoc { Id = doc1.Id, Name = "Wrong" };
    theSession.UpdateRevision(doc2, doc1.Version + 1);
    await theSession.SaveChangesAsync();

    theSession.Logger = new TestOutputMartenLogger(_output);

    await Should.ThrowAsync<ConcurrencyException>(async () =>
    {
        theSession.UpdateRevision(doc2, 2);
        theSession.SaveChanges();
    });
}

Stack Trace: 
AutoClosingLifetime.ExecuteBatchPagesAsync(IReadOnlyList1 pages, List1 exceptions, CancellationToken token) line 347
AutoClosingLifetime.ExecuteBatchPagesAsync(IReadOnlyList1 pages, List1 exceptions, CancellationToken token) line 369
AutoClosingLifetime.ExecuteBatchPagesAsync(IReadOnlyList1 pages, List1 exceptions, CancellationToken token) line 369
<b__2_0>d.MoveNext()
--- End of stack trace from previous location ---
Outcome1.GetResultOrRethrow() ResiliencePipeline.ExecuteAsync[TState](Func3 callback, TState state, CancellationToken cancellationToken)
DocumentSessionBase.ExecuteBatchAsync(IUpdateBatch batch, CancellationToken token) line 192
ExceptionTransformExtensions.TransformAndThrow(IEnumerable`1 transforms, Exception ex)
DocumentSessionBase.ExecuteBatchAsync(IUpdateBatch batch, CancellationToken token) line 199
DocumentSessionBase.ExecuteBatchAsync(IUpdateBatch batch, CancellationToken token) line 216
DocumentSessionBase.SaveChangesAsync(CancellationToken token) line 99
numeric_revisioning.optimistic_concurrency_failure_with_update_revision() line 173
--- End of stack trace from previous location ---

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

1 participant