Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to update a related collection within an afterChange hook when using postgres #10222

Closed
CCoffie opened this issue Dec 28, 2024 · 3 comments

Comments

@CCoffie
Copy link

CCoffie commented Dec 28, 2024

Describe the Bug

There seems to be a bug within the postgres implementation that's not allowing afterChange hooks to update other collection items. I created a test project that shows the bug. The test project works when I switch to using mongo as the backend but when using postgres, the action times out.

Link to the code that reproduces this issue

https://github.com/CCoffie/payload-bug

Reproduction Steps

  1. Run the test project with npm run dev. (I currently have a docker compose up command for postgres running as a predev command)
  2. Go to the admin panel and create a credit transaction
  3. Set the required fields and submit and the action will freeze

It seems to freezing on this section of the hook:

const updatedUser = await payload.update({
      collection: 'users',
      id: user.id,
      data: {
        credits: newCredits,
      },
    })

Which area(s) are affected? (Select all that apply)

db-postgres, area: core

Environment Info

Binaries:
  Node: 22.11.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: 9.12.3
Relevant Packages:
  payload: 3.9.0
  next: 15.1.0
  @payloadcms/db-mongodb: 3.11.0
  @payloadcms/db-postgres: 3.9.0
  @payloadcms/email-nodemailer: 3.9.0
  @payloadcms/graphql: 3.9.0
  @payloadcms/next/utilities: 3.9.0
  @payloadcms/payload-cloud: 3.9.0
  @payloadcms/richtext-lexical: 3.9.0
  @payloadcms/translations: 3.9.0
  @payloadcms/ui/shared: 3.9.0
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-5 (2024-12-03T10:26Z)
  Available memory (MB): 16384
  Available CPU cores: 4
@CCoffie CCoffie added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Dec 28, 2024
@akhrarovsaid
Copy link
Contributor

akhrarovsaid commented Dec 28, 2024

Hey @CCoffie,

Can you try passing req to your payload.update call? See here for info

const updatedUser = await payload.update({
  collection: 'users',
  id: user.id,
  data: {
    credits: newCredits,
  },
  req
})

@CCoffie
Copy link
Author

CCoffie commented Dec 28, 2024

Ah, yep that fixed it! Thanks for the help. Should the req parameter always be passed?

@akhrarovsaid
Copy link
Contributor

@CCoffie Generally yes, wherever you have access to a req you want to pass it in. It's highly recommended at least.

@CCoffie CCoffie closed this as completed Dec 28, 2024
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Dec 28, 2024
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

No branches or pull requests

2 participants