Skip to content

Preserve array element converters with explicit column types - #4007

Merged
roji merged 1 commit into
mainfrom
roji-issue-3636-triage
Oct 18, 2026
Merged

roji merged 1 commit into
mainfrom
roji-issue-3636-triage

Conversation

@roji

@roji roji commented Oct 18, 2026

Copy link
Copy Markdown
Member

Explicit array column types such as text[] currently discard custom element converters, causing stored values and queries to use enum names instead of the configured strings.

Pass the resolved element mapping into array mapping resolution. When its store type differs from the explicit column type, resolve the requested type using the converter's provider CLR type and compose the original converter onto it, retaining comparers and JSON metadata. Explicit column-type precedence is preserved, including int[] mapped to bigint[]; convention-selected converters are retained as well.

Regression coverage in ValueConvertersEndToEndNpgsqlTest checks inferred types, text[], and varchar(16)[] for stored strings, round-tripping, and Contains SQL. Unit coverage checks explicit integer/bigint array mappings with and without custom converters.

Fixes #3636

Retain element conversion metadata when resolving explicitly typed arrays while preserving column-type precedence. Cover custom enum conversion and explicit integer/bigint element mappings.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c376b6c6-fe3d-412c-819e-f125721cdbaa
Copilot AI balanced review requested due to automatic review settings October 18, 2026 09:53
@roji
roji merged commit 9357929 into main Oct 18, 2026
16 checks passed
@roji
roji deleted the roji-issue-3636-triage branch October 18, 2026 10:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Automatically inferred enum conversions change text-array representations and break compatibility with existing enum-name data.

1 open issue
What changed in this PR

Preserves array element converters when explicit PostgreSQL column types are configured, addressing #3636.

Changes:

  • Reuses or recomposes element mappings while honoring explicit store types.
  • Adds functional coverage for converted enum arrays.
  • Adds unit coverage for integer and bigint array mappings.
File Description
test/​EFCore.PG.Tests/​Storage/​NpgsqlTypeMappingSourceTest.cs Tests explicit array types with and without converters.
test/​EFCore.PG.FunctionalTests/​ValueConvertersEndToEndNpgsqlTest.cs Tests stored strings, round-tripping, and Contains queries.
src/​EFCore.PG/​Storage/​Internal/​NpgsqlTypeMappingSource.cs Preserves element converters during array mapping resolution.

Review effort: Balanced

relationalElementMapping = elementType is null
? FindMapping(elementStoreType)
: FindMapping(elementType, elementStoreType));
: FindMapping(elementMapping?.Converter?.ProviderClrType ?? elementType, elementStoreType);
roji added a commit that referenced this pull request Oct 18, 2026
…4011)

* [10.0] Preserve array element converters with explicit column types

Backport #4007 to hotfix/10.0.4. Retain element conversion metadata when resolving explicitly typed arrays while preserving column-type precedence.

(cherry picked from commit 9357929)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3c63e161-0531-4e0b-9756-a1eb6f999014

* Preserve explicit array element JSON mappings

Compose converters over the JSON reader/writer selected for the explicit element store type instead of restoring the inferred writer. This prevents timestamp arrays from reverting to timestamptz JSON serialization and breaking the JSON query/update fixtures.

Cover timestamp array JSON serialization with and without an element converter.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3c63e161-0531-4e0b-9756-a1eb6f999014

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3c63e161-0531-4e0b-9756-a1eb6f999014
roji added a commit that referenced this pull request Oct 18, 2026
…4014)

* [9.0] Preserve array element converters with explicit column types

Backport of #4007. Preserve explicit array column-type precedence and adapt the Contains SQL assertion to the 9.0 containment translation.

Fixes #3636

(cherry picked from commit 9357929)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bda9aa2e-f002-4257-9792-18a68ee0b9f2

* Preserve explicit array element JSON mappings

Port the correction from the 10.0 backport: compose converters over the JSON reader/writer selected for the explicit element store type instead of restoring the inferred writer. Cover timestamp array JSON serialization with and without an element converter.

(cherry picked from commit 842f9cd)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bda9aa2e-f002-4257-9792-18a68ee0b9f2

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bda9aa2e-f002-4257-9792-18a68ee0b9f2
roji added a commit that referenced this pull request Oct 18, 2026
…4013)

* [8.0] Preserve array element converters with explicit column types

Backport #4007 to hotfix/8.0.12. Preserve configured array element converters and explicit array store-type precedence. Adapt the regression SQL assertion to the 8.0 Contains translation.

(cherry picked from commit 9357929)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 79697333-2969-4518-b96e-46fe5fcb07c3

* Preserve explicit array element JSON mappings

Compose converters over the JSON reader/writer selected for the explicit element store type instead of restoring the inferred writer. Cover timestamp array JSON serialization with and without an element converter.

(cherry picked from commit 842f9cd)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 79697333-2969-4518-b96e-46fe5fcb07c3

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 79697333-2969-4518-b96e-46fe5fcb07c3
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.

ElementType().HasConversion() ignored when calling HasColumnType on PrimitiveCollection

2 participants