Skip to content

Postgres date fields error #8018

Open
Open
@haythaminteractivelifelb

Description

Moved From #7126 (comment) as requested by @r1tsuu

Link to reproduction

No response

Environment Info

Binaries:
  Node: 20.12.2
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  payload: 3.0.0-beta.96
  next: 15.0.0-canary.104
  @payloadcms/db-mongodb: 3.0.0-beta.96
  @payloadcms/db-postgres: 3.0.0-beta.96
  @payloadcms/email-nodemailer: 3.0.0-beta.96
  @payloadcms/graphql: 3.0.0-beta.96
  @payloadcms/live-preview: 3.0.0-beta.96
  @payloadcms/live-preview-react: 3.0.0-beta.96
  @payloadcms/next/utilities: 3.0.0-beta.96
  @payloadcms/plugin-cloud: 3.0.0-beta.96
  @payloadcms/plugin-cloud-storage: 3.0.0-beta.96
  @payloadcms/plugin-form-builder: 3.0.0-beta.96
  @payloadcms/plugin-nested-docs: 3.0.0-beta.96
  @payloadcms/plugin-redirects: 3.0.0-beta.96
  @payloadcms/plugin-seo: 3.0.0-beta.96
  @payloadcms/richtext-lexical: 3.0.0-beta.96
  @payloadcms/storage-s3: 3.0.0-beta.96
  @payloadcms/translations: 3.0.0-beta.96
  @payloadcms/ui/shared: 3.0.0-beta.96
  react: 19.0.0-rc-06d0b89e-20240801
  react-dom: 19.0.0-rc-06d0b89e-20240801
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 12102
  Available CPU cores: 8

Describe the Bug

I'm on Beta-96 with PostgreSQL 15 Database and I faced this issue from the start in 3.0.0-beta.42 with createdAt and updatedAt fields and I did a simple work around just for these 2 fields assuming that this is related only to this 2 fields. the solution was by adding this hook to all collections:

import type { CollectionBeforeChangeHook } from 'payload'

export const setTimestamps: CollectionBeforeChangeHook<any> = ({ data, collection }) => {
  const currentDate = new Date().toISOString()
  if (!data.createdAt) {
    data.createdAt = currentDate
  } else if (typeof data.createdAt !== 'string' && !(data.createdAt instanceof Date)) {
    data.createdAt = currentDate
  }

  if (!data.updatedAt) {
    data.updatedAt = currentDate
  } else if (typeof data.updatedAt !== 'string' && !(data.updatedAt instanceof Date)) {
    data.updatedAt = currentDate
  }
}

However after adding more date fields this issue came back to the Top as i added 2 new fields

    {
      name: 'one_consent_date',
      type: 'date'
    },
    {
      name: 'two_consent_date',
      type: 'date'
    }

and I was able to save them, at the start i thought that I cannot but after that I noticed that I'm able to save it for some users and not others.

the error is :

error: invalid input syntax for type timestamp with time zone: "{}"
    at eval (webpack-internal:///(rsc)/./node_modules/pg-pool/index.js:45:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async eval (webpack-internal:///(rsc)/./node_modules/drizzle-orm/node-postgres/session.js:60:22)

Reproduction Steps

As explained above!
After further debugging I've noticed that the issue is coming from another Date Field resetPasswordExpiration, so if the user resettled his password, he will got this date issue all the time as I cannot find a work around for this field!

Adapters and Plugins

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions