Repository navigation
Fix byte-array projections from JSON collections - #4067
Merged
Merged
Conversation
Decode base64 text extracted by json_to_recordset and jsonb_to_recordset before using binary properties in projections or predicates. Add sync/async regression coverage for json and jsonb, including null and empty payloads. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: dbf67848-d1a3-45a1-a202-1b7161746a53
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: dbf67848-d1a3-45a1-a202-1b7161746a53
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: dbf67848-d1a3-45a1-a202-1b7161746a53
This was referenced Oct 22, 2026
roji
added a commit
that referenced
this pull request
Oct 22, 2026
Backport #4067, retaining the late JSON postprocessor and its comments. Adapt regression coverage to EF9 owned ToJson collection mapping for json/jsonb, sync/async, null/empty payloads, and binary equality. Fixes #3566 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f9d39831-0c6c-4de0-9216-259844517ec4
roji
added a commit
that referenced
this pull request
Oct 22, 2026
Backport #4067 using EF8 table identities and owning selects to decode base64 recordset fields without wrapper subqueries. Add owned-JSON regression coverage, including correlated references. Fixes #3566 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c8a1b67d-06d1-4128-b3e6-3679f8634267
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 #3566.
json_to_recordset/jsonb_to_recordsetdo not decode the base64 representation used forbyte[]properties inside JSON. Collection expansion therefore returned the base64 text's bytes, even though full-document materialization and indexed property access returned the original payload.Related upstream fix: dotnet/efcore#33440, which fixed dotnet/efcore#33435. That addressed the same base64-versus-binary-conversion mismatch in SQL Server's scalar JSON access by rewriting
JSON_VALUEtoOPENJSON ... WITH. This PR addresses PostgreSQL's separate collection-recordset path; Npgsql's scalar JSON decoding already works. The late JSON postprocessing approach follows the same upstream precedent while retaining flat PostgreSQL SQL.Extract affected recordset columns as
textand wrap their references indecode(..., 'base64'). This is applied after structural projection expansion, which requires column expressions, and avoids adding SQL subqueries. Existing scalar JSON decoding is unchanged.Add sync/async regression coverage using complex JSON collection mapping in the shared JSON translation fixture for both
jsonandjsonb, comparing full materialization with projected bytes and checking server-side binary equality. Include non-ASCII bytes, empty arrays, and null values.Confirmed with a standalone console repro on released providers 8.0.0, 9.0.4, 10.0.0, 10.0.3, and unmodified main. The equivalent collection projection works with SQL Server 10.0.0. The original repro returns matching bytes after the fix. Manual checks also confirmed owned and complex JSON mapping.
Validation:
dotnet test --project test/EFCore.PG.FunctionalTests --filter-class '*Json*'— 1,757 passed, 9 skipped, using an isolated PostgreSQL Testcontainer. After switching the regression to complex mapping, the affectedJsonTranslationsNpgsqlTestsuite passed all 12 cases.This is a bug fix targeting main (11.0), not a new JSON feature or a serialization-format change. No backports are included.