Base solution for your next web application
Open Closed

Disabling LastModifierUserId auditing is not working within a job #12163


User avatar
0
Ricavir created

Hi support team,

I'm facing an issue with abp 9.3.0. We have a bacground job that updates some tenant data. Data is being saved successfuly.

I wanted to avoid loosing LastModifierUserId in this case.

Thus, I'm using UnitOfWorkManager.Current.DisableAuditing(AbpAuditFields.LastModifierUserId, AbpAuditFields.LastModificationTime)

But this is only preventing LastModificationTime to be updated. LastModifierUserId is being saved as null value and I don't understand why.

Here is the code :

public class UpdateStatusJob : AsyncBackgroundJob<UpdateStatusJobArgs>, ITransientDependency
{
    private readonly IDataManager _dataManager;
    private readonly IUnitOfWorkManager _unitOfWorkManager;
    private readonly IInvoiceManager _invoiceManager;

    public UpdateStatusJob(IDataManager dataManager,
                              IInvoiceManager invoiceManager,
                              IUnitOfWorkManager unitOfWorkManager)
    {
        _unitOfWorkManager = unitOfWorkManager;
        _dataManager = dataManager;
        _invoiceManager = invoiceManager;
    }

    public override async Task ExecuteAsync(UpdateStatusJobArgs args)
    {
        await _unitOfWorkManager.WithUnitOfWorkAsync(async () =>
        {
            using (UnitOfWorkManager.Current.SetTenantId(args.TenantId))
            {
                using (UnitOfWorkManager.Current.DisableAuditing(AbpAuditFields.LastModifierUserId, AbpAuditFields.LastModificationTime))
                {                    
                    if (args.InvoiceId.HasValue)
                    {
                        //Initialize job 
                        var invoiceReport = await _invoiceManager.GetInvoice(args.InvoiceId.Value);
                        var updateResult = await _dataManager.UpdateStatus(invoiceReport, args.TenantId);
                        if (updateResult.Success == false)
                        {
                            new Exception("Updating invoice status failed !");
                        }
                    }
                }
            }
        });
    }
}

I can see in debug that LastModifierUserId is disabled in current UOW. When looking at the logs, I can see following SQL request :

UPDATE [AbpTenants] SET [AdditionalCreditAmount] = @p0
OUTPUT 1
WHERE [Id] = @p1;
UPDATE [LInvoices] SET [Status] = @p2, [IsCreditUsed] = @p3, [LastModifierUserId] = @p4
OUTPUT 1
WHERE [Id] = @p5;

I've tested several ways to begin UOW but the issue is always the same.

Do you see something wrong here ? Is it a bug on the framework ?


4 Answer(s)
  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @Ricavir,

    I tested this in ANZ dev branch. When I use the following code. It worked as expected.

    using (UnitOfWorkManager.Current.DisableAuditing(AbpAuditFields.LastModifierUserId,
               AbpAuditFields.LastModificationTime))
    {
    
  • User Avatar
    0
    Ricavir created

    Hi @m.aliozkaya,

    Thanks for this feedback. I also use it in other parts of the code without any issue.

    Did you try doing it from a background job like I did ?

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @Ricavir,

    You are correct. I reproduced the problem. I'm creating an issue for it. Both values are updated even though I disabled it in my test.

    https://github.com/aspnetzero/aspnet-zero-core/issues/5414

  • User Avatar
    0
    Ricavir created

    Great ! Thank you