Skip to content

fix(adapter-ppg): handle null values in type parsers for nullable columns#29192

Merged
jacek-prisma merged 7 commits intoprisma:mainfrom
veeceey:fix/issue-29190-nullable-datetime-adapter-ppg
Feb 18, 2026
Merged

fix(adapter-ppg): handle null values in type parsers for nullable columns#29192
jacek-prisma merged 7 commits intoprisma:mainfrom
veeceey:fix/issue-29190-nullable-datetime-adapter-ppg

Conversation

@veeceey
Copy link
Copy Markdown
Contributor

@veeceey veeceey commented Feb 14, 2026

Fixes #29190

The PPG client passes null values through to type parsers for nullable columns, unlike the standard pg client. This causes a TypeError: Cannot read properties of null (reading 'replace') when querying models with nullable DateTime?, TimeTZ, Money, or Bytea columns that have null values in the database.

Added null guards to the following parser functions in packages/adapter-ppg/src/conversion.ts:

  • normalize_timestamp
  • normalize_timestamptz
  • normalize_timez
  • normalize_money
  • convertBytes

The other parsers (normalize_bool, normalize_date, normalize_time, normalize_numeric, toJson, normalize_xml, normalizeBit) either already handle null or simply pass through the value without calling methods on it, so they don't crash.

Summary by CodeRabbit

  • Bug Fixes

    • Improved null-tolerant parsing across booleans, arrays, timestamps, timestamptz, time-with-zone, money, and binary values so empty or missing inputs are preserved instead of erroring.
    • Public parsers now consistently propagate null-safe behavior.
  • Tests

    • Added comprehensive tests covering null handling and normalization for timestamps, timestamptz, timetz, money, bool, and binary parsing.
  • Chores

    • Expanded CI to run unit tests for the adapter package.

The PPG client passes null values through to type parsers for nullable
columns, unlike the standard pg client. This causes TypeError when
calling .replace() or .slice() on null for nullable DateTime, TimeTZ,
Money, and Bytea columns.

Fixes prisma#29190
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 14, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 14, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Normalization utilities and parser mappings in packages/adapter-ppg/src/conversion.ts were made null-safe: several normalizers and byte/array converters now accept string | null and return nullable results. Tests and CI were added to validate null handling for multiple scalar and array types.

Changes

Cohort / File(s) Summary
Normalization & parsers
packages/adapter-ppg/src/conversion.ts
Exported ArrayColumnType and updated signatures/logic for normalize_bool, normalize_array, normalize_timestamp, normalize_timestamptz, normalize_timez, normalize_money, normalizeByteaArray, and convertBytes to accept `string
Unit tests
packages/adapter-ppg/src/conversion.test.ts
Added tests exercising null handling and normalization for TIMESTAMP, TIMESTAMPTZ (various offsets), TIMETZ, MONEY, BOOL, BYTEA and their array forms; includes helper to fetch parsers by OID and validates Buffer conversions.
CI workflow
.github/workflows/test-template.yml
Added a test step to run pnpm run test for packages/adapter-ppg under the driver-adapter-unit-tests job to include the new test suite in CI.
🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding null-value handling to type parsers in adapter-ppg for nullable columns.
Linked Issues check ✅ Passed The PR comprehensively addresses #29190 by adding null guards to all affected parsers (normalize_timestamp, normalize_timestamptz, normalize_timez, normalize_money, convertBytes, and array variants) and includes tests as requested.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing null-handling in type parsers: signature updates, null guards in conversion.ts, tests in conversion.test.ts, and CI integration.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/adapter-ppg/src/conversion.ts (1)

313-315: ⚠️ Potential issue | 🟠 Major

normalize_array and normalizeByteaArray lack null guards that other normalizers have.

If a nullable array column contains SQL NULL, the parsers will receive null and throw. Other scalar normalizers guard against this (e.g., normalize_bool, normalize_timestamp, convertBytes). Both normalize_array and normalizeByteaArray should return null early if the input is null, consistent with the established pattern.

The null guards were correct but the parameter types still declared
string, making the null checks appear as dead code under
strictNullChecks. This widens the types to string | null so the
contract is honest and the compiler can enforce the guards.

Also fixes normalize_bool for consistency.
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/adapter-ppg/src/conversion.ts (1)

313-315: ⚠️ Potential issue | 🟡 Minor

normalize_array's element normalizer type is incompatible with nullable normalizers under strictFunctionTypes.

normalize_array expects (x: string) => string, but normalize_timestamp, normalize_timestamptz, normalize_money, and normalize_bool return string | null. With strict: true enabled in the TypeScript configuration, this violates return type covariance and causes a type error.

Widen the signature to accept and return nullable values:

Proposed fix
-function normalize_array(element_normalizer: (x: string) => string): (str: string) => string[] {
-  return (str) => parseArray(str, element_normalizer)
+function normalize_array(element_normalizer: (x: string) => string | null): (str: string) => (string | null)[] {
+  return (str) => parseArray(str, element_normalizer)
 }

…le array columns

Addresses CodeRabbit review feedback: widen normalize_array element_normalizer
signature to accept string | null returns, add null input handling to both
normalize_array and normalizeByteaArray to prevent TypeError on nullable
array columns with SQL NULL values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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

@veeceey
Copy link
Copy Markdown
Contributor Author

veeceey commented Feb 16, 2026

@CLAassistant check

@jacek-prisma
Copy link
Copy Markdown
Contributor

jacek-prisma commented Feb 16, 2026

Thank you for the contribution!
It'd be nice to cover this with some test. Unfortunately the PPG adapter isn't tested within our functional test suite, which would be the best way to test this. As a second resort, I think we can just add a conversion.test.ts, which would test the parsing behavior in isolation. You can see unit tests in other adapters for reference, for example packages/adapter-mssql/src/conversion.test.ts. Then make sure it's included in CI via .github/workflows/test-template.yml (look for working-directory: packages/adapter-*).

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 16, 2026

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 30 skipped benchmarks1


Comparing veeceey:fix/issue-29190-nullable-datetime-adapter-ppg (a89e8aa) with main (3fd1431)

Open in CodSpeed

Footnotes

  1. 30 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Add unit tests covering null handling in type parsers (timestamp,
timestamptz, timez, money, bool, bytes) and normal value parsing.
Include adapter-ppg in the driver-adapter-unit-tests CI job.
Also add explicit return type annotation to normalizeByteaArray.
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: 2

@veeceey
Copy link
Copy Markdown
Contributor Author

veeceey commented Feb 17, 2026

Hi Prisma team, just a gentle bump on this PR. All CodeRabbit suggestions have been addressed — null guards added for all affected parser functions including arrays, type signatures widened, and return type annotations added. The fix prevents TypeError crashes for nullable DateTime, TimeTZ, Money, and Bytea columns in the PPG adapter. Would appreciate a human review when someone has a chance!

Copy link
Copy Markdown
Contributor

@jacek-prisma jacek-prisma left a comment

Choose a reason for hiding this comment

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

There's one valid CodeRabbit comment and a type error: src/conversion.test.ts(112,14): error TS18047: 'result' is possibly 'null'
If these get addressed, I would be happy to merge this.

Copy link
Copy Markdown

@zrosenbauer zrosenbauer left a comment

Choose a reason for hiding this comment

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

LGTM

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: 3

@jacek-prisma jacek-prisma merged commit 9618edc into prisma:main Feb 18, 2026
252 of 253 checks passed
jacek-prisma added a commit that referenced this pull request Feb 19, 2026
…umns (#29192)

Fixes #29190

The PPG client passes null values through to type parsers for nullable
columns, unlike the standard pg client. This causes a `TypeError: Cannot
read properties of null (reading 'replace')` when querying models with
nullable `DateTime?`, `TimeTZ`, `Money`, or `Bytea` columns that have
null values in the database.

Added null guards to the following parser functions in
`packages/adapter-ppg/src/conversion.ts`:
- `normalize_timestamp`
- `normalize_timestamptz`
- `normalize_timez`
- `normalize_money`
- `convertBytes`

The other parsers (`normalize_bool`, `normalize_date`, `normalize_time`,
`normalize_numeric`, `toJson`, `normalize_xml`, `normalizeBit`) either
already handle null or simply pass through the value without calling
methods on it, so they don't crash.

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

* **Bug Fixes**
* Improved null-tolerant parsing across booleans, arrays, timestamps,
timestamptz, time-with-zone, money, and binary values so empty or
missing inputs are preserved instead of erroring.
  * Public parsers now consistently propagate null-safe behavior.

* **Tests**
* Added comprehensive tests covering null handling and normalization for
timestamps, timestamptz, timetz, money, bool, and binary parsing.

* **Chores**
  * Expanded CI to run unit tests for the adapter package.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Jacek Malec <malec@prisma.io>
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.

adapter-ppg doesn't handle nullable DateTime, it failes on normalize_timestamp with null access (.replace)

4 participants