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

Problem with SeedDataAsync(tenant) with some tanants in database. BUG #21256

Open
wenceslaoleon opened this issue Nov 5, 2024 · 1 comment
Open

Comments

@wenceslaoleon
Copy link

ABP Framework version 8.3.1
User Interface MVC
database provider(EF Core)

[22:12:38 INF] Started database migrations...
[22:13:26 INF] Migrating schema for host database...
[22:13:34 INF] Executing host database seed...
[22:13:38 INF] Successfully completed host database migrations.
[22:13:53 INF] Executing Ball y Compañía Ltda tenant database seed...
[22:13:54 ERR] Error migrating database for tenant Ball y Compañía Ltda (Id: 66f0ee4d-8af1-513c-e3a1-3a1044f8348f).
Volo.Abp.AbpException: Both id and name can't be invalid.
at Volo.Abp.MultiTenancy.TenantConfigurationCacheItem.CalculateCacheKey(Nullable1 id, String name) at Volo.Abp.TenantManagement.TenantConfigurationCacheItemInvalidator.ClearCacheAsync(Nullable1 id, String normalizedName)
at Volo.Abp.TenantManagement.TenantConfigurationCacheItemInvalidator.HandleEventAsync(EntityChangedEventData1 eventData) at Volo.Abp.EventBus.EventHandlerInvoker.InvokeAsync(IEventHandler eventHandler, Object eventData, Type eventType) at Volo.Abp.EventBus.Local.LocalEventBus.InvokeEventHandlerAsync(IEventHandler eventHandler, Object eventData, Type eventType) at Volo.Abp.EventBus.EventBusBase.TriggerHandlerAsync(IEventHandlerFactory asyncHandlerFactory, Type eventType, Object eventData, List1 exceptions, InboxConfig inboxConfig)
at System.AbpExceptionExtensions.ReThrow(Exception exception)
at Volo.Abp.EventBus.EventBusBase.ThrowOriginalExceptions(Type eventType, List1 exceptions) at Volo.Abp.EventBus.EventBusBase.TriggerHandlersAsync(Type eventType, Object eventData) at Volo.Abp.EventBus.Local.LocalEventBus.PublishAsync(LocalEventMessage localEventMessage) at Volo.Abp.EventBus.Local.LocalEventBus.PublishToEventBusAsync(Type eventType, Object eventData) at Volo.Abp.EventBus.Local.LocalEventBus.PublishAsync(Type eventType, Object eventData, Boolean onUnitOfWorkComplete) at Volo.Abp.EventBus.UnitOfWorkEventPublisher.PublishLocalEventsAsync(IEnumerable1 localEvents)
at Volo.Abp.Uow.UnitOfWork.CompleteAsync(CancellationToken cancellationToken)
at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed)
at CostaConsulting.Compliance.Data.ComplianceDbMigrationService.SeedDataAsync(Tenant tenant) in C:\dev\Compliance\src\CostaConsulting.Compliance.Domain\Data\ComplianceDbMigrationService.cs:line 159
at CostaConsulting.Compliance.Data.ComplianceDbMigrationService.MigrateAsync() in C:\dev\Compliance\src\CostaConsulting.Compliance.Domain\Data\ComplianceDbMigrationService.cs:line 127
[22:13:58 INF] Executing demo1 tenant database seed...
[22:13:59 ERR] Error migrating database for tenant demo1 (Id: 8ed888b2-4b2c-213c-d1f7-3a0bd74cb460).
Volo.Abp.AbpException: Both id and name can't be invalid.
at Volo.Abp.MultiTenancy.TenantConfigurationCacheItem.CalculateCacheKey(Nullable1 id, String name) at Volo.Abp.TenantManagement.TenantConfigurationCacheItemInvalidator.ClearCacheAsync(Nullable1 id, String normalizedName)
at Volo.Abp.TenantManagement.TenantConfigurationCacheItemInvalidator.HandleEventAsync(EntityChangedEventData1 eventData) at Volo.Abp.EventBus.EventHandlerInvoker.InvokeAsync(IEventHandler eventHandler, Object eventData, Type eventType) at Volo.Abp.EventBus.Local.LocalEventBus.InvokeEventHandlerAsync(IEventHandler eventHandler, Object eventData, Type eventType) at Volo.Abp.EventBus.EventBusBase.TriggerHandlerAsync(IEventHandlerFactory asyncHandlerFactory, Type eventType, Object eventData, List1 exceptions, InboxConfig inboxConfig)
at System.AbpExceptionExtensions.ReThrow(Exception exception)
at Volo.Abp.EventBus.EventBusBase.ThrowOriginalExceptions(Type eventType, List1 exceptions) at Volo.Abp.EventBus.EventBusBase.TriggerHandlersAsync(Type eventType, Object eventData) at Volo.Abp.EventBus.Local.LocalEventBus.PublishAsync(LocalEventMessage localEventMessage) at Volo.Abp.EventBus.Local.LocalEventBus.PublishToEventBusAsync(Type eventType, Object eventData) at Volo.Abp.EventBus.Local.LocalEventBus.PublishAsync(Type eventType, Object eventData, Boolean onUnitOfWorkComplete) at Volo.Abp.EventBus.UnitOfWorkEventPublisher.PublishLocalEventsAsync(IEnumerable1 localEvents)
at Volo.Abp.Uow.UnitOfWork.CompleteAsync(CancellationToken cancellationToken)
at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed)
at CostaConsulting.Compliance.Data.ComplianceDbMigrationService.SeedDataAsync(Tenant tenant) in C:\dev\Compliance\src\CostaConsulting.Compliance.Domain\Data\ComplianceDbMigrationService.cs:line 159
at CostaConsulting.Compliance.Data.ComplianceDbMigrationService.MigrateAsync() in C:\dev\Compliance\src\CostaConsulting.Compliance.Domain\Data\ComplianceDbMigrationService.cs:line 127
[22:13:59 INF] Executing SKConverge tenant database seed...
[22:14:00 ERR] Error migrating database for tenant SKConverge (Id: fd36a396-2785-a242-e81b-3a0ce9d865d9).
Volo.Abp.AbpException: Both id and name can't be invalid.
at Volo.Abp.MultiTenancy.TenantConfigurationCacheItem.CalculateCacheKey(Nullable1 id, String name) at Volo.Abp.TenantManagement.TenantConfigurationCacheItemInvalidator.ClearCacheAsync(Nullable1 id, String normalizedName)
at Volo.Abp.TenantManagement.TenantConfigurationCacheItemInvalidator.HandleEventAsync(EntityChangedEventData1 eventData) at Volo.Abp.EventBus.EventHandlerInvoker.InvokeAsync(IEventHandler eventHandler, Object eventData, Type eventType) at Volo.Abp.EventBus.Local.LocalEventBus.InvokeEventHandlerAsync(IEventHandler eventHandler, Object eventData, Type eventType) at Volo.Abp.EventBus.EventBusBase.TriggerHandlerAsync(IEventHandlerFactory asyncHandlerFactory, Type eventType, Object eventData, List1 exceptions, InboxConfig inboxConfig)
at System.AbpExceptionExtensions.ReThrow(Exception exception)
at Volo.Abp.EventBus.EventBusBase.ThrowOriginalExceptions(Type eventType, List1 exceptions) at Volo.Abp.EventBus.EventBusBase.TriggerHandlersAsync(Type eventType, Object eventData) at Volo.Abp.EventBus.Local.LocalEventBus.PublishAsync(LocalEventMessage localEventMessage) at Volo.Abp.EventBus.Local.LocalEventBus.PublishToEventBusAsync(Type eventType, Object eventData) at Volo.Abp.EventBus.Local.LocalEventBus.PublishAsync(Type eventType, Object eventData, Boolean onUnitOfWorkComplete) at Volo.Abp.EventBus.UnitOfWorkEventPublisher.PublishLocalEventsAsync(IEnumerable1 localEvents)
at Volo.Abp.Uow.UnitOfWork.CompleteAsync(CancellationToken cancellationToken)
at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed)
at CostaConsulting.Compliance.Data.ComplianceDbMigrationService.SeedDataAsync(Tenant tenant) in C:\dev\Compliance\src\CostaConsulting.Compliance.Domain\Data\ComplianceDbMigrationService.cs:line 159
at CostaConsulting.Compliance.Data.ComplianceDbMigrationService.MigrateAsync() in C:\dev\Compliance\src\CostaConsulting.Compliance.Domain\Data\ComplianceDbMigrationService.cs:line 127
[22:14:00 INF] Executing WOM tenant database seed...
[22:14:00 ERR] Error migrating database for tenant WOM (Id: 4a284082-a263-8112-5c72-3a0e31a6d10f).
Volo.Abp.AbpException: Both id and name can't be invalid.
at Volo.Abp.MultiTenancy.TenantConfigurationCacheItem.CalculateCacheKey(Nullable1 id, String name) at Volo.Abp.TenantManagement.TenantConfigurationCacheItemInvalidator.ClearCacheAsync(Nullable1 id, String normalizedName)
at Volo.Abp.TenantManagement.TenantConfigurationCacheItemInvalidator.HandleEventAsync(EntityChangedEventData1 eventData) at Volo.Abp.EventBus.EventHandlerInvoker.InvokeAsync(IEventHandler eventHandler, Object eventData, Type eventType) at Volo.Abp.EventBus.Local.LocalEventBus.InvokeEventHandlerAsync(IEventHandler eventHandler, Object eventData, Type eventType) at Volo.Abp.EventBus.EventBusBase.TriggerHandlerAsync(IEventHandlerFactory asyncHandlerFactory, Type eventType, Object eventData, List1 exceptions, InboxConfig inboxConfig)
at System.AbpExceptionExtensions.ReThrow(Exception exception)
at Volo.Abp.EventBus.EventBusBase.ThrowOriginalExceptions(Type eventType, List1 exceptions) at Volo.Abp.EventBus.EventBusBase.TriggerHandlersAsync(Type eventType, Object eventData) at Volo.Abp.EventBus.Local.LocalEventBus.PublishAsync(LocalEventMessage localEventMessage) at Volo.Abp.EventBus.Local.LocalEventBus.PublishToEventBusAsync(Type eventType, Object eventData) at Volo.Abp.EventBus.Local.LocalEventBus.PublishAsync(Type eventType, Object eventData, Boolean onUnitOfWorkComplete) at Volo.Abp.EventBus.UnitOfWorkEventPublisher.PublishLocalEventsAsync(IEnumerable1 localEvents)
at Volo.Abp.Uow.UnitOfWork.CompleteAsync(CancellationToken cancellationToken)
at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed)
at CostaConsulting.Compliance.Data.ComplianceDbMigrationService.SeedDataAsync(Tenant tenant) in C:\dev\Compliance\src\CostaConsulting.Compliance.Domain\Data\ComplianceDbMigrationService.cs:line 159
at CostaConsulting.Compliance.Data.ComplianceDbMigrationService.MigrateAsync() in C:\dev\Compliance\src\CostaConsulting.Compliance.Domain\Data\ComplianceDbMigrationService.cs:line 127
[22:14:00 INF] Successfully completed all database migrations.
[22:14:00 INF] You can safely end this process...

if I run DbMkigrator, I get this error,

I have this problems, when updating production database, I need help asap.

Volo.Abp.AbpException: Both id and name can't be invalid.

here

public async Task MigrateAsync()
{
    var initialMigrationAdded = AddInitialMigrationIfNotExist();

    if (initialMigrationAdded)
    {
        return;
    }

    Logger.LogInformation("Started database migrations...");

    await MigrateDatabaseSchemaAsync();
    await SeedDataAsync();

    Logger.LogInformation($"Successfully completed host database migrations.");

    var tenants = await _tenantRepository.GetListAsync(includeDetails: true);

    var migratedDatabaseSchemas = new HashSet<string>();
    foreach (var tenant in tenants)
    {
        try
        {
            using (_currentTenant.Change(tenant.Id, tenant.Name))
            {
                if (tenant.ConnectionStrings.Any())
                {
                    var tenantConnectionStrings = tenant.ConnectionStrings
                        .Select(x => x.Value)
                        .ToList();

                    if (!migratedDatabaseSchemas.IsSupersetOf(tenantConnectionStrings))
                    {
                        await MigrateDatabaseSchemaAsync(tenant);

                        migratedDatabaseSchemas.AddIfNotContains(tenantConnectionStrings);
                    }
                }

                await SeedDataAsync(tenant);
            }

            Logger.LogInformation("Successfully completed {tenantName} tenant database migrations.", tenant.Name);
        }
        catch (Exception ex)
        {
            // Registro del error específico del tenant sin interrumpir el proceso completo
            Logger.LogError(ex, "Error migrating database for tenant {tenantName} (Id: {tenantId}).", tenant.Name, tenant.Id);
        }
    }

    Logger.LogInformation("Successfully completed all database migrations.");
    Logger.LogInformation("You can safely end this process...");
}

private async Task SeedDataAsync(Tenant tenant = null)
{
    Logger.LogInformation("Executing {tenant} database seed...", (tenant == null ? "host" : tenant.Name + " tenant"));

    await _dataSeeder.SeedAsync(new DataSeedContext(tenant?.Id)
        .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, IdentityDataSeedContributor.AdminEmailDefaultValue)
        .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, IdentityDataSeedContributor.AdminPasswordDefaultValue)
    );
}
@wenceslaoleon wenceslaoleon changed the title Problem with SeedDataAsync(tenant) with some tanants in database. Problem with SeedDataAsync(tenant) with some tanants in database. BUG Nov 7, 2024
@maliming
Copy link
Member

hi

Can you check your tenant table in the database?

the NormalizedName of all tenants should have a value.

https://abp.io/docs/latest/release-info/migration-guides/abp-8-1#added-normalizedname-property-to-tenant

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