Enhance query filter expansion safety by adding validation for non-lambda transformers#78
Open
koenbeuk wants to merge 1 commit into
Open
Enhance query filter expansion safety by adding validation for non-lambda transformers#78koenbeuk wants to merge 1 commit into
koenbeuk wants to merge 1 commit into
Conversation
…mbda transformers
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens EF Core global query filter expansion by validating that expression transformers preserve the required LambdaExpression shape, preventing silent query filter removal (which could unintentionally widen data access) when SetQueryFilter(null) is invoked.
Changes:
- Added an explicit validation step during model finalization to ensure expanded query filters remain lambdas, throwing an
InvalidOperationExceptionotherwise. - Added an integration test that verifies model building fails loudly when a transformer returns a non-lambda expression for a query filter.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests/Tests/Sqlite/QueryFilterExpansionSafetyTests.cs | Adds a regression test proving non-lambda transformer output during query filter expansion fails model creation with a clear error. |
| src/ExpressiveSharp.EntityFrameworkCore/Infrastructure/Internal/ExpressiveExpandQueryFiltersConvention.cs | Introduces safe query filter expansion via a helper that prevents silent filter removal by requiring LambdaExpression output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+57
to
+64
| var expanded = filter.ExpandExpressives(_options); | ||
| if (expanded is not LambdaExpression lambda) | ||
| { | ||
| throw new InvalidOperationException( | ||
| $"Expanding the query filter for entity type '{entityType.DisplayName()}' produced a " + | ||
| $"{expanded.NodeType} expression instead of a lambda, which would silently remove the filter. " + | ||
| "A registered IExpressionTreeTransformer must return a LambdaExpression when given one."); | ||
| } |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.