Skip to content

Fail closed when data filters cannot be applied to compiled queries - #26284

Merged
ismcagdas merged 5 commits into
rel-10.7from
maliming/compiled-query-filters
Oct 15, 2026
Merged

ismcagdas merged 5 commits into
rel-10.7from
maliming/compiled-query-filters

Conversation

@maliming

@maliming maliming commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Related to #26282

With UseDbFunction, the soft delete and multi-tenant filter translations treated a missing current DbContext as a disabled filter, so EF.CompileQuery and EF.CompileAsyncQuery ran without these filters. They now throw an AbpException. ABP wraps IDatabase and 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.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 06:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 18.16940% with 599 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.89%. Comparing base (57a0332) to head (494a8c8).
⚠️ Report is 9 commits behind head on rel-10.7.

Files with missing lines Patch % Lines
...ing/CompiledQueryCache/CompiledQueryCache_Tests.cs 0.00% 189 Missing ⚠️
...ction/ServiceCollectionDecorateExtensions_Tests.cs 0.00% 85 Missing ⚠️
...eryCache/CompiledQueryCache_QueryCompiler_Tests.cs 0.00% 45 Missing ⚠️
...edQueryCache/AbpDbContextOptionsExtension_Tests.cs 0.00% 43 Missing ⚠️
...iledQueryCache/CompiledQueryCacheTestModuleBase.cs 0.00% 40 Missing ⚠️
...g/CompiledQueryCache/CompiledQueryCacheTestBase.cs 0.00% 34 Missing ⚠️
...ache/CompiledQueryCache_WithoutDbFunction_Tests.cs 0.00% 33 Missing ⚠️
...dQueryCache/CompiledQueryCacheTestQueryCompiler.cs 0.00% 25 Missing ⚠️
...yCache/CompiledQueryCache_DatabaseFactory_Tests.cs 0.00% 24 Missing ⚠️
.../CompiledQueryCache/CompiledQueryCacheTestHooks.cs 0.00% 21 Missing ⚠️
... and 13 more
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@maliming
maliming requested a review from ismcagdas October 14, 2026 07:43
@maliming maliming added this to the 10.7-final milestone Oct 14, 2026
@maliming
maliming requested a balanced review from Copilot October 14, 2026 07:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The security-sensitive tenant isolation change depends on EF Core internal query compiler APIs and warrants final human validation.

0 open findings

🧠 Review effort: Balanced

@ismcagdas ismcagdas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/en/release-info/migration-guides/abp-10-7.md Outdated
Comment thread docs/en/framework/infrastructure/data-filtering.md Outdated
@maliming
maliming requested a review from ismcagdas October 15, 2026 03:45
@ismcagdas
ismcagdas merged commit 6cadc53 into rel-10.7 Oct 15, 2026
3 checks passed
@ismcagdas
ismcagdas deleted the maliming/compiled-query-filters branch October 15, 2026 07:35
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

Successfully merging this pull request may close these issues.

3 participants