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

Custom Table Query batched with a regular document insert causes ResetAll to fail #2523

Closed
dgrozenok opened this issue Mar 8, 2023 · 1 comment · Fixed by #2570
Closed

Comments

@dgrozenok
Copy link

dgrozenok commented Mar 8, 2023

Here is the test project with the failing unit test:

https://github.com/dgrozenok/MartenCustomStorageTest

The key code causing the issue is that both session.QueueSqlCommand and session.Insert are in the same unit of work before the call to session.SaveChangesAsync

        var store = DocumentStore.For(_ =>
        {
            _.Connection("HOST=localhost; DATABASE='postgres'; USER ID='postgres'; PASSWORD='Password12!'");
            _.Storage.Add<CustomTableStorage>();
        });
        await store.Schema.ApplyAllConfiguredChangesToDatabaseAsync();
        await using var session = store.LightweightSession();
        session.QueueSqlCommand(CustomTableStorage.InsertSql, Guid.NewGuid().ToString());
        session.Insert(new User(Guid.NewGuid().ToString(), "John Doe"));
        await session.SaveChangesAsync();
        await store.Advanced.ResetAllData();

The exception in store.Advanced.ResetAllData():

Marten.Exceptions.InvalidDocumentException
Could not determine an 'id/Id' field or property for requested document type Marten.Storage.StorageFeatures
   at Marten.Schema.DocumentMapping.CompileAndValidate()
   at Marten.Storage.DocumentTable..ctor(DocumentMapping mapping)
   at Marten.Schema.DocumentSchema..ctor(DocumentMapping mapping)
   at Marten.Schema.DocumentMapping.<.ctor>b__7_0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Marten.Schema.DocumentMapping.get_Schema()
   at Marten.Storage.StorageFeatures.AllActiveFeatures(IMartenDatabase database)+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at Marten.Storage.MartenDatabase.BuildFeatureSchemas()
   at Weasel.Core.Migrations.DatabaseBase`1.AllObjects()
   at Weasel.Core.Migrations.DatabaseBase`1.AllSchemaNames()
   at Marten.Storage.MartenDatabase.DeleteAllDocumentsAsync(CancellationToken ct)
   at Marten.Storage.MartenDatabase.DeleteAllDocumentsAsync(CancellationToken ct)
   at Marten.AdvancedOperations.ResetAllData(CancellationToken cancellation)
   at MartenCustomStorageTest.ResetAllTest.WhenCustomTableIsUsedInABatchWithOtherDocumentResetAllShouldWork() in /Users/dgrozenok/RiderProjects/MartenCustomStorageTest/ResetAllTest.cs:line 21
   at MartenCustomStorageTest.ResetAllTest.WhenCustomTableIsUsedInABatchWithOtherDocumentResetAllShouldWork() in /Users/dgrozenok/RiderProjects/MartenCustomStorageTest/ResetAllTest.cs:line 21
   at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_0.<<InvokeTestMethodAsync>b__1>d.MoveNext() in /_/src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs:line 264
--- End of stack trace from previous location ---
   at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in /_/src/xunit.execution/Sdk/Frameworks/ExecutionTimer.cs:line 48
   at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.core/Sdk/ExceptionAggregator.cs:line 90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants