Thank you, I was under the mistaken impression that IMultiTenant was not mandatory for a Split Tenant Schema scenario. This resolved my issue.
I'm aware of the ICurrentTenant.Change method and how it's supposed to switch DB Context.
Despite ICurrentTenant.Change being called twice (first in TestSeedProjectTenantDatabaseMigrationHandler.cs and then again in BookStoreDataSeederContributor.cs), the seeder seems to revert to the host database context for unknown reasons.
TestSeedProjectTenantDatabaseMigrationHandler.cs: ICurrentTenant.Change is called, seemingly setting the correct tenant context prior to the call to _dataSeeder.SeedAsync.
BookStoreDataSeederContributor.cs: The tenant context appears correct initially (due to already being called in TestSeedProjectTenantDatabaseMigrationHandler.cs) and ICurrentTenant.Change is called again in the BookStoreDataSeederContributor.cs class (as a precaution and per your suggestion). When the seeder attempts to access the tenant-only table, it queries the host schema instead.
The tenant context is not being maintained consistently throughout the seeding process, even though ICurrentTenant.Change is called multiple times.
Video 1: Shows the AppBooks table correctly created in the tenant schema. - https://youtube.com/shorts/HOEFQNgWc-I Video 2: Demonstrates the seeder querying the host schema after ICurrentTenant.Change, even though the correct tenant context seems to be already selected. - https://youtu.be/yAGVvT6NvQc
ABP Framework with split tenant schema
Any guidance on how to ensure the data seeder correctly uses the tenant database context would be greatly appreciated.
Additional Notes: It seems that the TestSeedProjectTenantDatabaseMigrationHandler.cs already switches the tenant context using ICurrentTenant.Change within a unit of work before calling the _dataSeeder.SeedAsync method. This is why the Books data seeder shows the correct tenant context initially. The issue is isolated to the data seeding process. Database migrations and schema creation work as expected.
you can pull the lastest from the github project and see the error in action.
I added shiwei.liang@volosoft.com to the git repo. Please let me know if I need to add someone else.
They seem to be related since both are having exception when HandleEventAsync(EntityUpdatedEto) is called. I will go ahead and open another ticket but they do seem to be happening in exactly the same spot just in different project.
Hello liangshiwei,
When I attempt to run automated tests within my project after applying patch I receive the following issue when attempting to execute automated tests. This seems to also be related to the original issue as AggregateException on EntityUpdatedEto is being thrown in the test project. Do I also need to apply a patch to the TestBase? If so, where should patch be applied?
All tests within the project fail.
` MyProject.Timeclock.TimeclockTests.FiveMinuteRoundingTimeShouldCalculateAsExpectedAsync(value1: 2021-01-01T01:09:00.0000000, expected: 2021-01-01T01:10:00.0000000) Source: TimeclockTests.cs line 248 Duration: 1 ms
Message:
Volo.Abp.AbpInitializationException : An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module MyProject.MyProjectTestBaseModule, MyProject.TestBase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: More than one error has occurred while triggering the event: Volo.Abp.Domain.Entities.Events.Distributed.EntityUpdatedEto1[Volo.Abp.Users.UserEto] (SqliteConnection does not support nested transactions.) (SqliteConnection does not support nested transactions.). See the inner exception for details. ---- System.AggregateException : More than one error has occurred while triggering the event: Volo.Abp.Domain.Entities.Events.Distributed.EntityUpdatedEto1[Volo.Abp.Users.UserEto] (SqliteConnection does not support nested transactions.) (SqliteConnection does not support nested transactions.)
-------- System.InvalidOperationException : SqliteConnection does not support nested transactions.
-------- System.InvalidOperationException : SqliteConnection does not support nested transactions.
Stack Trace:
ModuleManager.InitializeModules(ApplicationInitializationContext context)
AbpApplicationBase.InitializeModules()
AbpIntegratedTest1.ctor() TimeclockTests.ctor() line 21 RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions) ----- Inner Stack Trace ----- EventBusBase.ThrowOriginalExceptions(Type eventType, List1 exceptions)
EventBusBase.TriggerHandlersAsync(Type eventType, Object eventData)
LocalEventBus.PublishAsync(LocalEventMessage localEventMessage)
LocalEventBus.PublishToEventBusAsync(Type eventType, Object eventData)
<47 more frames...>
DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
AbpDbContext1.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) UnitOfWork.SaveChangesAsync(CancellationToken cancellationToken) UnitOfWork.CompleteAsync(CancellationToken cancellationToken) UserLookupService2.WithNewUowAsync(Func1 func) UserLookupService2.FindByIdAsync(Guid id, CancellationToken cancellationToken)
CmsUserSynchronizer.HandleEventAsync(EntityUpdatedEto1 eventData) EventHandlerInvoker.InvokeAsync(IEventHandler eventHandler, Object eventData, Type eventType) EventBusBase.TriggerHandlerAsync(IEventHandlerFactory asyncHandlerFactory, Type eventType, Object eventData, List1 exceptions, InboxConfig inboxConfig)`
Hi,
Could you share the steps to reproduce or a project that can reproduce the problem with me via email? shiwei.liang@volosoft.com thanks.
Hello liangshiwei,
I created a new project at version 5.2.1. I then opened abp suite and added the chat module package.
I then implemented customized login flow as described here https://github.com/abpframework/abp-samples/tree/master/SignInWithoutSpecifyingTenant.
I then logged in using host account and created a new tenant. I then enabled the chat feature within the tenant standard edition. I then upgraded abp packages to 5.3.4 using abp suite.
When I login with tenant using incorrect password, I am getting error when wrong password is used. Although the error in my example git repo is a little different than my original error, root cause seems to be the same. It appears for some reason an attempt is made to insert a duplicate chat user.
Please see repo @ https://github.com/jarrad78shoplogic/Testest.git
The above replicates what we did in our own project. We were running 5.2.1 and using a customized login flow for signin without specifying tenant. When we upgraded to 5.3.4 the error began for us in same manner as in the sample above.
I figured out to add TenantId field to DTO object, I then overrode the base crud app service method, I then add TenantId to the DTO prior to sending the updated DTO object to base CRUD method. Is this correct approach?
You can also inject ICurrentTenant to your application service to get the current tenant information.
I can get the ICurrentTenant without issue, is there any way to have the sub-entities update when using the IRepository UpdateAsync method? Currently when I attempt to update via IRepository UpdateAsync method, the parent entity updates as expected but the attached child entities are all marked as isDeleted = true and none of the updates are applied to the sub-entites upon save. It's strange because when I debug, the results are exactly as expected and show the correct information, but after the resultDTO object is sent back to the browser, then the sub-entities are being marked as deleted in the database.
I figured out to add TenantId field to DTO object, I then overrode the base crud app service method, I then add TenantId to the DTO prior to sending the updated DTO object to base CRUD method. Is this correct approach?