Skip to content

Emit a deprecation warning when serializing an invalid Date - #3731

Open
charmander with Copilot wants to merge 1 commit into
masterfrom
copilot/fix-serialize-invalid-date
Open

Emit a deprecation warning when serializing an invalid Date#3731
charmander with Copilot wants to merge 1 commit into
masterfrom
copilot/fix-serialize-invalid-date

Conversation

Copilot AI commented Aug 7, 2026

Copy link
Copy Markdown

new Date(undefined) (or any invalid Date) is silently serialized to "0NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN", a string Postgres cannot meaningfully parse, leading to confusing downstream errors instead of a clear signal at the source.

Changes

  • packages/pg/lib/utils.js: prepareValue now emits a util.deprecate-based process warning (code PG_INVALID_DATE) when serializing an invalid Date, without changing the current serialized output, for backwards compatibility. The warning explains that this will become an error in the next major version of pg.
  • packages/pg/test/unit/utils-tests.js: added a unit test asserting prepareValue emits the PG_INVALID_DATE warning and still serializes the invalid date to the existing (garbage) string.
const { Client } = require('pg')
const client = new Client()

// Still serializes to "0NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN" today,
// but now also emits a DeprecationWarning (code PG_INVALID_DATE)
await client.query('INSERT INTO events (occurred_at) VALUES ($1)', [new Date(undefined)])

Copilot AI changed the title [WIP] Fix serialization of new Date(undefined) as Invalid date Throw an error when serializing an invalid Date instead of sending garbage to Postgres Aug 7, 2026
Copilot AI requested a review from charmander August 7, 2026 03:03
@cloudflare-workers-and-pages

This comment was marked as off-topic.

Copilot stopped work on behalf of charmander due to an error August 7, 2026 03:24
@charmander charmander changed the title Throw an error when serializing an invalid Date instead of sending garbage to Postgres Emit a deprecation warning when serializing an invalid Date Aug 7, 2026
Co-authored-by: charmander <1889843+charmander@users.noreply.github.com>
@charmander
charmander force-pushed the copilot/fix-serialize-invalid-date branch from 20b8068 to 7781972 Compare August 7, 2026 04:03
@charmander
charmander requested a balanced review from Copilot August 7, 2026 04:05

This comment was marked as resolved.

@charmander
charmander marked this pull request as ready for review August 7, 2026 04:09
@charmander
charmander requested a review from brianc August 7, 2026 04:20
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.

Do not serialize new Date(undefined) as "0NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN"

3 participants