Improve handling of null values in JSON properties mapped to primitive collections#38498
Draft
AndriySvyryd wants to merge 1 commit into
Draft
Improve handling of null values in JSON properties mapped to primitive collections#38498AndriySvyryd wants to merge 1 commit into
AndriySvyryd wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #38454 by improving materialization behavior when JSON contains the null token for primitive collections (both when mapped to a dedicated column and when nested inside a JSON document), aiming to return null for optional properties and throw a clearer, property-named exception for required ones.
Changes:
- Add a shaper-side fast path for primitive collections mapped to columns to detect JSON
nullbefore invokingCollectionToJsonStringConverter<>. - Improve error reporting for required primitive collections nested in JSON by throwing
RelationalStrings.NullValueInRequiredJsonProperty(...)instead of a reader/writer token-type exception. - Add functional tests covering nullable/required primitive collections and converter
ConvertsNullsbehavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/EFCore.SqlServer.FunctionalTests/Query/AdHocJsonQuerySqlServerTestBase.cs | Adds SQL Server functional tests for JSON null handling in primitive collections and converter null-conversion semantics. |
| src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs | Updates the shaper expression generation to special-case primitive collection column materialization and to throw clearer errors for required JSON collections. |
| src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.ClientMethods.cs | Introduces an internal helper used by the shaper to parse primitive collection JSON strings and handle the null token. |
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.
Fixes #38454
Changes materialization behavior when JSON contains the
nulltoken for primitive collections (both when mapped to a dedicated column and when nested inside a JSON document), aiming to returnnullfor optional properties and throw a clearer, property-named exception for required ones.Changes:
nullbefore invokingCollectionToJsonStringConverter<>.RelationalStrings.NullValueInRequiredJsonProperty(...)instead of a reader/writer token-type exception.ConvertsNullsbehavior.