Open Closed

Inconsistent data saving in the Database #8379


User avatar
0
Anjaneyulu created
  • ABP Framework version: v8.3.0
  • UI Type: MVC
  • Database System: EF Core (SQL Server
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue: 1. Created the project

This is in UserDirectoryService in application layer

public virtual async Task<ADBaseResponse> ImportUsersAsync(ADUserObjectInputArgs input)
{
    //Enqueue job with delay and priority
    if(input.TenantId == null)
    {
        input.TenantId = this.CurrentTenant.Id;
    }
    await _backgroundJobManager.EnqueueAsync<ADUserObjectInputArgs>(input, BackgroundJobPriority.Normal);
    return new ADBaseResponse() { Status = true, Message = "Users Syncing Initiated" };
}

**Backgroundjob: which is in domain layer**
[DisallowConcurrentExecution]
public class ADUsersManualSyncJob : AsyncBackgroundJob<ADUserObjectInputArgs>, ITransientDependency
{
    //private readonly ICancellationTokenProvider _cancellationTokenProvider;
    protected UserDirectoryManager UserDirectoryManager;
    protected UserDirectoryFilterManager UserDirectoryFilterManager;
    private readonly ADManagerService ADManagerServices;
    protected UserManagementService UserManagementServices;
    public ADUsersManualSyncJob(
        //ICancellationTokenProvider cancellationTokenProvider,
        UserDirectoryManager userDirectoryManager,
        UserDirectoryFilterManager userDirectoryFilterManager, ADManagerService aDManagerService, UserManagementService userManagementServices
        )
    {
        //_cancellationTokenProvider = cancellationTokenProvider;
        UserDirectoryManager = userDirectoryManager;
        UserDirectoryFilterManager = userDirectoryFilterManager;
        ADManagerServices = aDManagerService;
        UserManagementServices = userManagementServices;
    }

    [UnitOfWork]
    public override async Task ExecuteAsync(ADUserObjectInputArgs args)
    {
        //_cancellationTokenProvider.Token.ThrowIfCancellationRequested();

        var directoryServiceData = await UserDirectoryManager.GetDirectoryById(args.DirectoryId);
        if (directoryServiceData != null)
        {
            var resp = await ProcessAsync(userData, args.TenantId, userInfo.UserAttributes); // code omitted for brevity
                            if(resp == null)
                            {
                                //TODO...
                            }var 
        }
    }

    private async Task<IdentityUser> ProcessAsync(CreateUserorUpdateInput input, Guid? tenantId, IDictionary<string, string> additionalAttributes)
    {
        //TODO...
        var userInfo = await UserManagementServices.CreateUserAsync(input, tenantId, additionalAttributes);
        return userInfo;
        // need to call the create user function to onboard the user from Usermanagement Services...
    }

**this is the create user function which is in user management service manager which is in domain layer**
************************************************************************************************************************************************
public class UserManagementService : ITransientDependency
{
    protected IdentityUserManager _userManager { get; }
    private readonly IIdentityRoleRepository RoleRepository;
    private readonly IIdentityUserRepository _xSenseIdentityUserRepository;

    protected UserDirectoryManager _userDirectoryManager { get; }

    protected IOptions<IdentityOptions> IdentityOptions { get; }
    public UserManagementService(IdentityUserManager userManager, IIdentityRoleRepository roleRepository, UserDirectoryManager userDirectoryManager,
        IIdentityUserRepository xSenseIdentityUserRepository)
    {
        _userDirectoryManager = userDirectoryManager;
        _userManager = userManager;
        RoleRepository = roleRepository;
        _xSenseIdentityUserRepository = xSenseIdentityUserRepository;
    }

    public bool CanCreateUserAsync(Guid? input)
    {
        try
        {
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }

    [UnitOfWork]
    public async Task<IdentityUser> CreateUserAsync(CreateUserorUpdateInput input,Guid? tenantId,IDictionary<string,string> additionalAttributes = null)
    {
        try
        {
            if(CanCreateUserAsync(tenantId))
            {
                var user = new IdentityUser(
                input.Id,
                input.UserName,
                input.Email,
                tenantId)
                {
                    IsExternal = true,
                    Surname = input.Surname,
                    Name = input.Name
                };
                user.SetIsActive(true);
                user.SetPhoneNumber(input.PhoneNumber, false);
                user.SetEmailConfirmed(input.EmailConfirmed);
                user.SetPhoneNumberConfirmed(input.PhoneNumberConfirmed);
                user.SetDirectoryId(input.DirectoryId);
                var dirObj = await _userDirectoryManager.GetDirectoryById(input.DirectoryId);
                user.SetDirectoryName(dirObj.Name);
                user.SetDirectoryType(dirObj.Type);
                input.MapExtraPropertiesTo(user);
                if(input.Password == null)
                {
                    input.Password = user.Id.ToString();
                }
                var roleeNames = RoleRepository.GetListAsync().Result.Where(r => r.IsDefault == true).Select(r => r.Name).ToArray();
                foreach (var item in additionalAttributes)
                {
                    user.SetExtraProperties(item.Key, item.Value);
                }
                user.SetExtraProperties("FilterId", input.FilterId.ToString());
                if(user !=  null)
                {
                    var userResp = await _xSenseIdentityUserRepository.InsertAsync(user);~~~~
                    return userResp;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
        catch (Exception ex)
        {
            return null;
        }
    }
    
}

Now the issue is, users are not getting created in database, even though i dont see any excption in the entire flow.

One more observation is the same code is working in a different machine. I want to understand what could be the issue.

Altough i have used Quartz for background job implementation, i have also have rabbitmq settings in the appsettings but have an issue connecting to rabbitmqserver . Hope that wont be an issue.


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

    Hi,

    you can try writing logs to check what happened.

    public class UserManagementService : ITransientDependency
    {
        protected IdentityUserManager _userManager { get; }
        private readonly IIdentityRoleRepository RoleRepository;
        private readonly IIdentityUserRepository _xSenseIdentityUserRepository;
        private readonly ILogger<UserManagementService> _logger;
    
        protected UserDirectoryManager _userDirectoryManager { get; }
    
        protected IOptions<IdentityOptions> IdentityOptions { get; }
        public UserManagementService(IdentityUserManager userManager, IIdentityRoleRepository roleRepository, UserDirectoryManager userDirectoryManager,
            IIdentityUserRepository xSenseIdentityUserRepository,ILogger<UserManagementService> logger)
        {
            _userDirectoryManager = userDirectoryManager;
            _userManager = userManager;
            RoleRepository = roleRepository;
            _xSenseIdentityUserRepository = xSenseIdentityUserRepository;
            _logger = logger;
        }
        
        ......
        
        _logger.LogInformation("Create user...");
        
    
  • User Avatar
    0
    Anjaneyulu created

    Hi , I could debug it, as i see the all the line are getting executed, and i even see the identityuser object response from the insert function.

    What should i log to get more information.

    Thanks

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    It's very strange, could you please share a test project with me? I will check it. shiwei.liang@volosoft.com

  • User Avatar
    0
    Anjaneyulu created

    If possible, I would like to connect with you and share the screen, so that we can have better context of it.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    It's better if you share project with me, I can check it in depth.

  • User Avatar
    0
    Anjaneyulu created

    Thanks, i got the issue. Issue seems to be with Rabbitmq for some reason.

    Altough i have configured the rabbitmq, application is not able to connect on 5672. Altough i didnt see any issue while debug, insertasync is throwing an expection after some time saying "not able to reach specific endpoint" rabbitmq server etc..,

    Once i fix the rabbitmq connection, im able see users in the DB

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Great to see that your solved the problem

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 25, 2025, 11:10