Fix tsvector columns over JSON-mapped navigations/complex properties#3893
Open
hostage2222 wants to merge 1 commit into
Open
Fix tsvector columns over JSON-mapped navigations/complex properties#3893hostage2222 wants to merge 1 commit into
hostage2222 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes design-time migration generation for generated tsvector columns when included names refer to JSON-mapped owned navigations or JSON-mapped complex properties (ToJson()), avoiding the previous NullReferenceException and adding regression coverage.
Changes:
- Extend
NpgsqlAnnotationProvidertsvector included-name resolution to handle JSON-mapped navigations and complex properties (resolving to the JSON container column). - Add a dedicated error string for unresolved included names (property/navigation/complex property).
- Add unit and functional regression tests for JSON-owned navigation/complex-property tsvector scenarios (including renamed/mixed cases).
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.PG.Tests/Migrations/NpgsqlAnnotationProviderTest.cs | Adds unit tests covering JSON navigation/complex-property included-name resolution and failure modes. |
| test/EFCore.PG.FunctionalTests/Migrations/MigrationsNpgsqlTest.cs | Adds functional migration test asserting SQL for generated tsvector over a JSON-owned navigation column. |
| src/EFCore.PG/Properties/NpgsqlStrings.resx | Introduces a new localized error message for unresolved included names. |
| src/EFCore.PG/Properties/NpgsqlStrings.Designer.cs | Adds the strongly-typed accessor for the new error message resource. |
| src/EFCore.PG/Metadata/Internal/NpgsqlAnnotationProvider.cs | Updates design-time annotation generation to resolve included names via properties, JSON navigations, or JSON complex properties. |
Files not reviewed (1)
- src/EFCore.PG/Properties/NpgsqlStrings.Designer.cs: Generated file
Comments suppressed due to low confidence (1)
src/EFCore.PG/Metadata/Internal/NpgsqlAnnotationProvider.cs:121
- The error text "Could not find property, navigation or complex property" is also used when the name does resolve to a navigation/complex property but isn't mapped to JSON (i.e. container column name can't be resolved). Consider rewording this message (or adding a separate one) to indicate that the included navigation/complex property must be mapped to a JSON container column via ToJson().
?? throw new InvalidOperationException(
NpgsqlStrings.TsVectorIncludedPropertyNotFound(valueGeneratedProperty.DeclaringType.DisplayName(), p2))
Comment on lines
+116
to
+121
| .Select(p2 => valueGeneratedProperty.DeclaringType.FindProperty(p2)?.GetColumnName(tableIdentifier) | ||
| ?? (valueGeneratedProperty.DeclaringType as IReadOnlyEntityType)?.FindNavigation(p2)?.TargetEntityType | ||
| .GetContainerColumnName(tableIdentifier) | ||
| ?? valueGeneratedProperty.DeclaringType.FindComplexProperty(p2)?.ComplexType.GetContainerColumnName(tableIdentifier) | ||
| ?? throw new InvalidOperationException( | ||
| NpgsqlStrings.TsVectorIncludedPropertyNotFound(valueGeneratedProperty.DeclaringType.DisplayName(), p2)) |
Author
There was a problem hiding this comment.
This isn't actually an issue. TargetEntityType and ComplexType are non-nullable properties. Due to how the null-conditional operator (?.) works, if FindNavigation(p2) or FindComplexProperty(p2) returns null, the entire expression short-circuits to null.
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.
When a property is configured as a generated tsvector column that includes a navigation or complex property mapped to JSON via
ToJson(),NpgsqlAnnotationProvideronly resolved included names as regular properties, throwing aNullReferenceExceptioninstead of finding the underlying JSON container column.Resolution now also checks navigations and complex properties declared on the same type, resolving them to their JSON container column (including renamed columns) and reporting a clear error for names that don't resolve to a property, navigation, or complex property. Adds unit and functional regression tests covering navigation- and complex-property-based JSON tsvector columns, including renamed and mixed scenarios.
Fixes #3075