Skip to content

EnableAllFilters() and DisableAllFilters() breaks conditionally enabled filters #146

@mlyczek

Description

@mlyczek

DynamicFilters version: 3.0.1
EntityFramework version: 6.1.3
Database version: SQL Server 2014

Example with failing unit test: https://github.com/mlyczek/EF.DynamicFilters.ConditionalEnableIssue

Hi, we are using EntityFramework.DynamicFilters in our project and it works great. But currently we want to use Conditionally Enabling Filters and we found out that there is probably an issue with it. In our project we use the DisableAllFilters() and EnableAllFilters() extension methods on DbContext in some scenarios where we want temporarily disable all our filters. The problem is that even after calling EnableAllFilters() our conditional filters are no longer calling the condition lambda to check whether they should be enabled or not. From that point those filters are always enabled.

In the repository linked above there is a test project where one test is failing to demonstrate the issue.

After a little debugging it looks like it is caused by the DisableAllFilters() and EnableAllFilters() methods. Both of them are calling GetOrCreateScopedFilterParameters() to get or create a scoped filter parameters definition in order to disable/enable the filter. The problem is that those scoped parameters definition doesn't have the EnableIfCondition property copied from original filter. And therefore while checking if the filter is enabled in IsFilterEnabled() that scoped parameters definition is found without EnableIfCondition and therefore IsFilterEnabled() returns true without calling the condition delegate.

Thanks in advance for looking into this issue.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions