Repository navigation
Fail closed when data filters cannot be applied to compiled queries - #26284
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
It changes tenant-isolation behavior through an EF Core internal service and warrants final human validation.
0 open findings
What changed in this PR
Prevents compiled EF Core queries from silently bypassing soft-delete and multi-tenant filters.
Changes:
- Adds a query compiler that clears ambient DbContext state during compiled-query creation.
- Throws when DbFunction-based filters lack a current DbContext.
- Adds regression tests and migration guidance.
| File | Description |
|---|---|
CompiledQueryCacheTestDbContext.cs |
Adds filter-specific test sets. |
CompiledQueryCacheTestBase.cs |
Adds compiled-query helpers. |
CompiledQueryCacheSoftDeleteRow.cs |
Adds soft-delete test entity. |
CompiledQueryCacheMultiTenantRow.cs |
Adds multi-tenant test entity. |
CompiledQueryCache_WithoutDbFunction_Tests.cs |
Verifies compiled queries remain supported without DbFunctions. |
CompiledQueryCache_Tests.cs |
Verifies compiled queries fail closed. |
AbpQueryCompiler.cs |
Clears ambient context during compilation. |
AbpDbContextOptionsExtension.cs |
Registers the custom compiler. |
AbpEfCoreModelBuilderExtensions.cs |
Rejects missing filter context. |
abp-10-7.md |
Documents migration impact. |
data-filtering.md |
Documents safe custom filter behavior. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## rel-10.7 #26284 +/- ##
============================================
- Coverage 50.05% 49.89% -0.16%
============================================
Files 3842 3857 +15
Lines 134429 135140 +711
Branches 10199 10243 +44
============================================
+ Hits 67285 67426 +141
- Misses 65131 65701 +570
Partials 2013 2013 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ismcagdas
left a comment
There was a problem hiding this comment.
Review notes. Nothing found here leaks data: compiled queries now throw instead of silently running without the soft-delete and tenant filters. The comments are about compatibility with custom IQueryCompiler implementations and about the docs. I have not built this or run the tests.
One item is outside the diff, so it can't be an inline comment:
docs/en/Community-Articles/2024-07-01-Use_User-Defined_Function_Mapping_For_Global_Filter/POST.md line 72: the article still shows abpEfCoreCurrentDbContext.Context?.DataFilter.IsEnabled<IIsActive>() == true. This PR removes that fail-open pattern from the built-in filters and from data-filtering.md. Anyone who copies the article's HasTranslation callback for a custom IIsActive filter gets this behavior: with EF.CompileQuery, Context is null and the filter becomes TRUE, so the query silently returns inactive rows instead of throwing like the built-in filters now do. Consider updating it to use GetRequiredContext(), or adding a note that points to the new guidance.
Related to #26282
With
UseDbFunction, the soft delete and multi-tenant filter translations treated a missing current DbContext as a disabled filter, soEF.CompileQueryandEF.CompileAsyncQueryran without these filters. They now throw anAbpException. ABP wrapsIDatabaseand only lets the query that went through the compiled query cache key generator read the current DbContext, so a nested compiled query can't use the outer query's filter state.