Avoid checking for null on non-nullable property for projection#6706
Avoid checking for null on non-nullable property for projection#6706glen-84 merged 25 commits intoChilliCream:mainfrom
Conversation
|
@PascalSenn Is this feasible? |
|
We did remove it once for ef core and then added it again: So i am not sure what to do now. I believe if you do not do the nullcheck then it will include all the fields from the child or something like this. |
|
You removed it completely, or conditionally based on the nullability of the property? Should I be seeing something significant in the test snapshots, or is there no test that would highlight the previous issue? If not, then I think that we need that test to exist in order to have some more confidence here. |
|
This is the context: So you only apply it when the property is nullable and ef does not complain? |
By "does not complain", you mean that the tests in |
|
This will quite likely fix these issues as well: |
8a97a79 to
e2d2300
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6706 +/- ##
==========================================
- Coverage 74.16% 0 -74.17%
==========================================
Files 2677 0 -2677
Lines 140790 0 -140790
Branches 16371 0 -16371
==========================================
- Hits 104421 0 -104421
+ Misses 30774 0 -30774
+ Partials 5595 0 -5595
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
4c0b153 to
88577d7
Compare
There was a problem hiding this comment.
Pull request overview
This pull request fixes issue #6604 where the projection middleware was generating null checks for non-nullable properties, causing EF Core 8 to throw an InvalidOperationException when comparing complex types to null. The fix adds nullability checking using NullabilityInfoContext to determine whether a property is nullable before adding the null check condition in the generated expression.
Changes:
- Modified
QueryableProjectionFieldHandlerto check property nullability before generating null checks - Added a new test file
QueryableProjectionComplexTypeTests.csto verify complex type projections work without inappropriate null checks - Updated 42 test snapshots showing removal of unnecessary constant expressions (like
1and1 AS "c") from generated SQL queries
Reviewed changes
Copilot reviewed 39 out of 39 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/HotChocolate/Data/src/Data/Projections/Expressions/Handlers/QueryableProjectionFieldHandler.cs | Added static NullabilityInfoContext instance and nullability check before adding null check expression |
| src/HotChocolate/Data/test/Data.Projections.SqlServer.Tests/QueryableProjectionComplexTypeTests.cs | New test file verifying that complex types project correctly without null checks |
| src/HotChocolate/Data/test/Data.Projections.SqlServer.Tests/snapshots/*.snap | Updated 42 snapshot files reflecting removal of unnecessary constant expressions in SQL |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 40 out of 40 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary of the changes (Less than 80 chars)
Closes #6604.