Repository navigation
Fix tsvector metadata cast for IReadOnlyList - #3984
Conversation
roji
left a comment
There was a problem hiding this comment.
Problem. #3892 is a genuine public metadata contract bug: both setters accept IReadOnlyList<string>, but the getter assumes string[]. For example:
property.SetTsVectorProperties(["Title"]);
property.GetTsVectorProperties(); // InvalidCastException before this fixnew List<string> { "Title" } fails in the same way; an actual array works. This also breaks Database.GenerateCreateScript(), so it is not just an isolated metadata-getter problem.
Expected approach. Cast to the declared interface in the shared getter and add a focused non-array regression test. No setter-side copying, new abstraction, API change, or documentation update is needed. The relational annotation provider already materializes an array of column names, preserving the downstream SQL generator's array assumption.
Assessment. The PR matches that approach exactly: one production-line change and a targeted regression test. The collection expression really does produce a non-array implementation with the repository's compiler; I confirmed that the added test fails on the original getter. The change is necessary, sufficient, and appropriately scoped.
Gaps. No blocking correctness or scope findings. I would take this change as written, without expanding it into broader metadata cleanup.
Manual validation. I applied a patch identical to this PR at ebfff5e7e14b0a6545d36751b52b52eda99c33fd and exercised a separate console application against the provider API, not only the unit tests. GenerateCreateScript() fails before the fix and succeeds afterward for collection expressions, List<string>, read-only collections, and arrays, using both mutable and convention setters. All eight fixed combinations produce the expected stored to_tsvector('english', "Title") generated column, without needing a running database. All 23 tests in NpgsqlMetadataExtensionsTest also pass. Version checks reproduce the original failure as far back as 5.0.0, so this is longstanding rather than a recent regression.
Posted by copilot
Backport of #3984 for #3892. (cherry picked from commit ebfff5e) Co-authored-by: Daniil Saushkin <[email protected]> Co-authored-by: Copilot App <[email protected]> Copilot-Session: e169ea65-4dce-4e7b-aeb7-8d0be894be49
Backport #3984 for #3892. (cherry picked from commit ebfff5e) Co-authored-by: Copilot App <[email protected]> Copilot-Session: 7b444553-37cd-4668-bf8f-a930eaabdb4d
Summary
Fixes #3892.
GetTsVectorProperties()previously cast the stored annotation tostring[], which caused anInvalidCastExceptionwhenSetTsVectorProperties()received a different implementation ofIReadOnlyList<string>.This change uses the declared interface type instead of assuming a specific collection implementation.
Changes
GetTsVectorProperties()to cast the annotation toIReadOnlyList<string>.Tests
Can_get_ts_vector_properties_from_read_only_list.NpgsqlMetadataExtensionsTest— all passed.