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

Intermittent Data-Filtering Bug within AsyncPeriodicBackgroundWorkerBase #20178

Open
1 task done
luy710 opened this issue Jul 6, 2024 · 2 comments
Open
1 task done

Comments

@luy710
Copy link

luy710 commented Jul 6, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Description

I'm encountering an issue with data filtering in my application, specifically within the AsyncPeriodicBackgroundWorkerBase class. Despite explicitly disabling the IIsActive filter using dataFilter.Disable(), there are occasional instances where the IsActiveFilterEnabled property remains enabled, leading to unexpected behavior in the generated SQL queries.

Reproduction Steps

AsyncPeriodicBackgroundWorkerBase
`using (dataFilter.Disable())
{
var query = await configRepository.GetQueryableAsync();
_logger.LogInformation($"000003:{parmQuery.ToQueryString()}");
var ts = Task.Run(async () => await Test2());
}

private async Task<Guid?> Test2()
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dataFilter = scope.ServiceProvider.GetService();
var configNoticeAppService = scope.ServiceProvider.GetService();

    using (dataFilter.Disable<IIsActive>())
    {
        var parmQuery = await _paramConfigRepository.GetQueryableAsync();
        _logger.LogInformation($"000004:{parmQuery.ToQueryString()}");
        return await configNoticeAppService.Testxx();
    }
}

}`

AbpDbContext
`protected bool IsActiveFilterEnabled => DataFilter?.IsEnabled() ?? false;

protected override bool ShouldFilterEntity(IMutableEntityType entityType)
{
return typeof(IIsActive).IsAssignableFrom(typeof(TEntity)) ? true : base.ShouldFilterEntity(entityType);
}

protected override Expression<Func<TEntity, bool>> CreateFilterExpression()
{
var expression = base.CreateFilterExpression();

if (typeof(IIsActive).IsAssignableFrom(typeof(TEntity)))
{
    var isActiveFilter = e => !IsActiveFilterEnabled || EF.Property<bool>(e, "IsActive");
    expression = expression == null 
        ? isActiveFilter 
        : QueryFilterExpressionHelper.CombineExpressions(expression, isActiveFilter);
}

return expression;

}`
The problem arises when the generated SQL occasionally still includes the IsActive filter even though it was intended to be disabled within the critical sections of the code.

Expected behavior

No response

Actual behavior

No response

Regression?

No response

Known Workarounds

No response

Version

8.0.0

User Interface

Common (Default)

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

@luy710 luy710 added the bug label Jul 6, 2024
@maliming
Copy link
Member

maliming commented Jul 8, 2024

hi

Please try to Disable filter in Test2 method.

@maliming maliming removed the bug label Jul 8, 2024
@luy710
Copy link
Author

luy710 commented Jul 9, 2024

hi

Please try to Disable filter in Test2 method.
already Disabled
`
private async Task<Guid?> Test2()
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dataFilter = scope.ServiceProvider.GetService();
var configNoticeAppService = scope.ServiceProvider.GetService();

    using (dataFilter.Disable<IIsActive>())
   {
        var parmQuery = await _paramConfigRepository.GetQueryableAsync();
        _logger.LogInformation($"000004:{parmQuery.ToQueryString()}");
        return await configNoticeAppService.Testxx();
   }
}

}`
_logger.LogInformation($"000004:{parmQuery.ToQueryString()}");
Log:
000004:DECLARE @__ef_filter__p_0 bit = CAST(0 AS bit);
DECLARE @__ef_filter__p_1 bit = CAST(0 AS bit);

SELECT [p].[Id], [p].[Address]
FROM [ppmexParamConfigs] AS [p]
WHERE (@__ef_filter__p_0 = CAST(1 AS bit) OR [p].[IsDeleted] = CAST(0 AS bit)) AND (@__ef_filter__p_1 = CAST(1 AS bit) OR [p].[IsActive]))

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