Skip to content

fix: add missing deserialization for JSON values#29182

Merged
jacek-prisma merged 5 commits intomainfrom
fix/fix-29174
Feb 18, 2026
Merged

fix: add missing deserialization for JSON values#29182
jacek-prisma merged 5 commits intomainfrom
fix/fix-29174

Conversation

@jacek-prisma
Copy link
Copy Markdown
Contributor

@jacek-prisma jacek-prisma commented Feb 13, 2026

TML-1901
Fixes #29174

Summary by CodeRabbit

  • Bug Fixes

    • Fixed JSON date deserialization in JSONB parameter fields to preserve date formatting and custom type info.
  • Refactor

    • Renamed exported deserialization function for clearer naming.
    • Raw JSON values are now preserved during deserialization.
    • Changed default behavior to wrap raw values during JSON serialization when option unspecified.
  • Tests

    • Added functional tests covering JSON date deserialization and related scenarios.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 13, 2026

Walkthrough

Renames deserializeJsonResponse to deserializeJsonObject and extends JSON tagged-value handling with a Raw variant. The rename is propagated through runtime, parameterization, and tests; JSON placeholder serialization now deserializes input before stringifying. Adds tests and schema for JSON(Date) regression and adjusts raw-wrapping default behavior.

Changes

Cohort / File(s) Summary
Client engine runtime — json protocol
packages/client-engine-runtime/src/json-protocol.ts, packages/client-engine-runtime/src/json-protocol.test.ts
Renamed exported entry from deserializeJsonResponsedeserializeJsonObject; added RawTaggedValue and included Raw in input/output tagged unions. Tests updated to use the new function name; deserializeTaggedValue handles 'Raw'.
Client engine runtime — batch usage
packages/client-engine-runtime/src/batch.ts
Replaced import/usage of deserializeJsonResponse with deserializeJsonObject in compacted rows deserialization.
Client runtime — request handling & index export
packages/client/src/runtime/RequestHandler.ts, packages/client/src/runtime/index.ts
Swapped import/export to use deserializeJsonObject from client-engine-runtime; unpack now calls deserializeJsonObject.
Client runtime — parameterization
packages/client/src/runtime/core/engines/client/parameterization/parameterize.ts
When serializing JSON placeholders, inputs are now passed through deserializeJsonObject before JSON.stringify, affecting array and object paths to avoid type-wrapping corruption.
Client runtime — JSON query serialization
packages/client/src/runtime/core/jsonProtocol/serializeJsonQuery.ts
Changed default of shouldWrapRawValues to true when wrapRawValues is undefined, altering raw argument wrapping behavior.
Functional tests for issue #29174
packages/client/tests/functional/issues/29174-jsonb-parameter-regression/_matrix.ts, packages/client/tests/functional/issues/29174-jsonb-parameter-regression/prisma/_schema.ts, packages/client/tests/functional/issues/29174-jsonb-parameter-regression/tests.ts
Added test matrix (excluding SQL Server), schema fixture, and tests verifying Date values in JSON fields serialize to ISO strings and preserve $type where applicable.
🚥 Pre-merge checks | ✅ 5 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding missing deserialization for JSON values to fix a JSONB regression.
Linked Issues check ✅ Passed The PR implements all required fixes: renames deserialization function, adds Raw value handling, updates JSON serialization logic, and includes regression tests for Date field serialization in JSONB.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the JSONB regression: deserialization function rename, Raw value handling, parameterization updates, and test coverage for the specific issue.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/fix-29174

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 13, 2026

Client memory tests, node 24, client:
❌ Failure, see report.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 13, 2026

size-limit report 📦

Path Size
packages/client/runtime/index-browser.js 2.23 KB (0%)
packages/client/runtime/index-browser.d.ts 3.28 KB (0%)
packages/cli/build/index.js 2.5 MB (0%)
packages/client/prisma-client-0.0.0.tgz 26.77 MB (+0.01% 🔺)
packages/cli/prisma-0.0.0.tgz 12.75 MB (0%)
packages/bundle-size/da-workers-libsql/output.tgz 1.32 MB (+0.01% 🔺)
packages/bundle-size/da-workers-neon/output.tgz 1.39 MB (+0.01% 🔺)
packages/bundle-size/da-workers-pg/output.tgz 1.38 MB (+0.01% 🔺)
packages/bundle-size/da-workers-planetscale/output.tgz 1.33 MB (+0.01% 🔺)
packages/bundle-size/da-workers-d1/output.tgz 1.3 MB (+0.01% 🔺)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 13, 2026

Client memory tests, node 22.12.0, client:
✅ Success

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 13, 2026

Client memory tests, node 20.19.0, client:
✅ Success

@jacek-prisma jacek-prisma requested a review from aqrln February 13, 2026 13:09
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 13, 2026

Merging this PR will not alter performance

✅ 47 untouched benchmarks


Comparing fix/fix-29174 (255bc72) with main (9865dcb)

Open in CodSpeed

@jacek-prisma jacek-prisma requested a review from aqrln February 18, 2026 09:51
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 18, 2026
@aqrln aqrln added this to the 7.4.1 milestone Feb 18, 2026
@jacek-prisma jacek-prisma merged commit 344ccd5 into main Feb 18, 2026
255 of 256 checks passed
@jacek-prisma jacek-prisma deleted the fix/fix-29174 branch February 18, 2026 12:14
jacek-prisma added a commit that referenced this pull request Feb 19, 2026
[TML-1901](https://linear.app/prisma-company/issue/TML-1901/investigate-and-fix-jsonb-regression-in-74)
Fixes #29174

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Fixed JSON date deserialization in JSONB parameter fields to preserve
date formatting and custom type info.

* **Refactor**
  * Renamed exported deserialization function for clearer naming.
  * Raw JSON values are now preserved during deserialization.
* Changed default behavior to wrap raw values during JSON serialization
when option unspecified.

* **Tests**
* Added functional tests covering JSON date deserialization and related
scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
jacek-prisma pushed a commit that referenced this pull request Feb 27, 2026
Fixes #29267

## Problem

`Uint8Array` values nested inside objects or arrays are serialized as
numeric-keyed objects (e.g. `{"0":72,"1":101,"2":108,"3":108,"4":111}`)
instead of base64 strings when stored in a `Json` field. Top-level
`Uint8Array` values are unaffected.

This was introduced in #29182, which added `deserializeJsonObject()`
before `JSON.stringify()` in the parameterization step to fix Date
handling in Json fields. `deserializeJsonObject` correctly converts `{
$type: 'Bytes', value: 'SGVsbG8=' }` back to a `Uint8Array`, but
`JSON.stringify` cannot natively serialize `Uint8Array` and falls back
to `{"0":72,...}`.

## Fix

Replace `JSON.stringify` with `safeJsonStringify` (already exported from
`@prisma/client-engine-runtime`) in both the `#handleArray` and
`#handleObject` methods of `Parameterizer`. `safeJsonStringify` uses a
custom replacer that converts `ArrayBuffer.isView` values to base64
strings and `BigInt` to string representation.

## Tests

Added a functional regression test in
`packages/client/tests/functional/issues/29267-uint8array-in-json/`
covering:
- `Uint8Array` nested inside an object
- `Uint8Array` nested inside an array
- `Uint8Array` passed directly (already working, included for
completeness)
- Deeply nested `Uint8Array`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

* **Bug Fixes**
* Improved JSON serialization for parameter handling to properly convert
Uint8Array values to base64 strings when stored in JSON fields, ensuring
correct data handling across create operations.

* **Tests**
* Added comprehensive test coverage for Uint8Array serialization in JSON
fields, including scenarios with nested objects, arrays, and various
nesting depths across multiple database providers.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
jacek-prisma pushed a commit that referenced this pull request Feb 27, 2026
Fixes #29267

## Problem

`Uint8Array` values nested inside objects or arrays are serialized as
numeric-keyed objects (e.g. `{"0":72,"1":101,"2":108,"3":108,"4":111}`)
instead of base64 strings when stored in a `Json` field. Top-level
`Uint8Array` values are unaffected.

This was introduced in #29182, which added `deserializeJsonObject()`
before `JSON.stringify()` in the parameterization step to fix Date
handling in Json fields. `deserializeJsonObject` correctly converts `{
$type: 'Bytes', value: 'SGVsbG8=' }` back to a `Uint8Array`, but
`JSON.stringify` cannot natively serialize `Uint8Array` and falls back
to `{"0":72,...}`.

## Fix

Replace `JSON.stringify` with `safeJsonStringify` (already exported from
`@prisma/client-engine-runtime`) in both the `#handleArray` and
`#handleObject` methods of `Parameterizer`. `safeJsonStringify` uses a
custom replacer that converts `ArrayBuffer.isView` values to base64
strings and `BigInt` to string representation.

## Tests

Added a functional regression test in
`packages/client/tests/functional/issues/29267-uint8array-in-json/`
covering:
- `Uint8Array` nested inside an object
- `Uint8Array` nested inside an array
- `Uint8Array` passed directly (already working, included for
completeness)
- Deeply nested `Uint8Array`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

* **Bug Fixes**
* Improved JSON serialization for parameter handling to properly convert
Uint8Array values to base64 strings when stored in JSON fields, ensuring
correct data handling across create operations.

* **Tests**
* Added comprehensive test coverage for Uint8Array serialization in JSON
fields, including scenarios with nested objects, arrays, and various
nesting depths across multiple database providers.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

postgres date field in JSONB serialization regression in 7.4.0

2 participants