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

Hooks hanging indefinitely on create operation to collection with relation back to triggering collection #7352

Closed
mcornielje090404 opened this issue Jul 25, 2024 · 6 comments
Assignees

Comments

@mcornielje090404
Copy link

mcornielje090404 commented Jul 25, 2024

Link to reproduction

https://github.com/mcornielje090404/payload-3.0-demo/tree/main

Payload Version

3.0.0-beta.67

Node Version

20.13.1

Next.js Version

15.0.0-canary.58

Describe the Bug

When attempting to run a payload "create" operation from within a hook on a collection that has a relation back to the original collection calling the hook the create operation hangs indefinitely.

If I remove the relation back to "posts" on the "posts-audits" collection in that repo the hook will run fine.

Reproduction Steps

  1. Spin up the repo linked
  2. Create a post
  3. The hook only runs on update so the initial creation will run fine
  4. Update the same post
  5. The hook will hang indefinitely at the create operation

Note: I have sometimes noticed the record is created but the promise never resolves.

Adapters and Plugins

db-postgres

@mcornielje090404 mcornielje090404 added status: needs-triage Possible bug which hasn't been reproduced yet v3 labels Jul 25, 2024
@mcornielje090404
Copy link
Author

I believe #6459 is related (an issue I previously raised) but I hadn't narrowed down the cause of the issue to being relations back to the triggering collection.

@mcornielje090404
Copy link
Author

I also suspect this happens on update operations

@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Jul 25, 2024
@jmikrut
Copy link
Member

jmikrut commented Jul 25, 2024

@JessChowdhury — please try and reproduce this with the example repo above - at first glance I suspected that this was an infinite loop caused by hook recursion but it does not appear to be so after looking at the code.

Not sure what exactly is causing this but it should be relatively easy to spot once you have this pulled up and reproducing reliably.

@JarrodMFlesch
Copy link
Contributor

JarrodMFlesch commented Jul 25, 2024

@mcornielje090404 does it finish if you pass the req through to your second payload.create operation?

i.e.

await payload.create({
  collection: 'post-audits',
  data: { ...strippedDoc, auditType },
  overrideAccess: true,
  user: req.user,
  req,
})

@JarrodMFlesch
Copy link
Contributor

@mcornielje090404 yeah, you just need to thread the req through as I did in the example above, tested and it updated as expected without hanging.

Copy link
Contributor

github-actions bot commented Sep 6, 2024

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants