Open Closed

Grpc Service Repository does not get any results from database #6387


User avatar
0
raymondbu95 created

Need help on the grpc service side. I was not able to get data through repository while using grpc service. That is weird because I was following the guide from https://docs.abp.io/en/commercial/7.4/startup-templates/microservice/using-grpc. Everything going okay except repository side did not return me the data it should. It keeps returns There is no such an entity but there is with the Id provided. I am using abp commercial for this. The grpc client is called from gateway and server is in microservice, not sure this will affect anything or not?

Attach with some images to help understand more on my situation.

  • ABP Framework version: v7.4.3
  • UI Type: MVC
  • Database System: EF Core (MySQL)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

5 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I guess it may be due to multi-tenant data isolation.

    You can check it by debugging or outputting logs:

    
    Guid tenantGuid = ....;
    logger.LogInformation($"------  TenantGuid is {tenantGuid}");
    using(CurrentTenant.Change(tenantGuid))
    {
        var apiSecretKey = Guid.Parse(request.ApiSecretKey);
        logger.LogInformation($"------  ApiSecretKey is {apiSecretKey}");
        var saasKeyChain = await _saasKeyChainRepository.FindAsync(apiSecretKey);
        if(saasKeyChain == null)
        {
            throw new UserFriendlyException(.....);
        }
    }
    
  • User Avatar
    0
    raymondbu95 created

    I did try debug and those keys are in position, just not sure why the repository does not give any results. Even I use FirstOrDefaultAsync(), still it returns empty. But i double check with my ApplicationAppService, that one works fine. Still cant figure out what is the issue. Or you mind to explain about the multi-tenant data isolation?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Or you mind to explain about the multi-tenant data isolation?

    Ok, if the entity implements a IMultiTenant interface. a tenant(and host) can not access to data of another tenant by default.

    https://docs.abp.io/en/abp/latest/Multi-Tenancy#imultitenant

    You can check the TenantId value in the database table record.

    According to your case, the ApiSecret 3a0f98fc-179f..... 's TenantId should be 3a0f9797-934e-16b0....

  • User Avatar
    0
    raymondbu95 created

    Hi,

    Or you mind to explain about the multi-tenant data isolation?

    Ok, if the entity implements a IMultiTenant interface. a tenant(and host) can not access to data of another tenant by default.

    https://docs.abp.io/en/abp/latest/Multi-Tenancy#imultitenant

    You can check the TenantId value in the database table record.

    According to your case, the ApiSecret 3a0f98fc-179f..... 's TenantId should be 3a0f9797-934e-16b0....

    Okay, I think this is the main issue causing me unable to get this current tenant's record from Repository. Anyway to access tenants's data through grpc? or grpc only can get host data?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can change the current tenant to get tenant data:

    using(CurrentTenant.Change(tenantGuid))
    {
        var saasKeyChain = await _saasKeyChainRepository.FindAsync(apiSecretKey);
        if(saasKeyChain == null)
        {
            throw new UserFriendlyException(.....);
        }
    }
    
Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11