Skip to content

Fix tsvector columns over JSON-mapped navigations/complex properties#3893

Open
hostage2222 wants to merge 1 commit into
npgsql:mainfrom
hostage2222:fix_tsvector_over_json
Open

Fix tsvector columns over JSON-mapped navigations/complex properties#3893
hostage2222 wants to merge 1 commit into
npgsql:mainfrom
hostage2222:fix_tsvector_over_json

Conversation

@hostage2222

Copy link
Copy Markdown

When a property is configured as a generated tsvector column that includes a navigation or complex property mapped to JSON via ToJson(), NpgsqlAnnotationProvider only resolved included names as regular properties, throwing a NullReferenceException instead 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

Copilot AI review requested due to automatic review settings July 24, 2026 14:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 NpgsqlAnnotationProvider tsvector 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))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

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.

NpgsqlTsVector HasGeneratedTsVectorColumn with Json Columns migration creation fails

2 participants