fix: add missing deserialization for JSON values#29182
Conversation
WalkthroughRenames Changes
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
packages/client/src/runtime/core/engines/client/parameterization/parameterize.ts
Show resolved
Hide resolved
|
Client memory tests, node 24, client: |
size-limit report 📦
|
|
Client memory tests, node 22.12.0, client: |
|
Client memory tests, node 20.19.0, client: |
[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 -->
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 -->
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 -->
TML-1901
Fixes #29174
Summary by CodeRabbit
Bug Fixes
Refactor
Tests