Giter Club home page Giter Club logo

Comments (5)

jmikrut avatar jmikrut commented on September 26, 2024

Hey @lekterable — I just reproduced this with your exact code and I can't seem to reproduce.

In order to help here, we're going to need you to provide a minimal reproduction - but I'd be happy to help once we can understand how to reproduce!

from payload.

lekterable avatar lekterable commented on September 26, 2024

huh, okay that's very strange, because the only thing that helped me was changing the adapter to Mongo

so you're able to query twice in the same hooks execution from the Postgres db? @jmikrut

I'll prepare a repro when I have a moment

from payload.

jmikrut avatar jmikrut commented on September 26, 2024

Yep. I did two consecutive finds in the same beforeValidate hook just as you did. And I logged the result for each find and both worked accordingly.

Are you setting max connections or anything like that? One thing you could try is to pass the req through to your find queries in your hook, so that the Payload operations are all running on the same transaction / connection.

Every time you do a payload.find or any local API method, Payload will either:

  1. Start a new transaction
  2. Use the same transaction that already exists if you pass the req as an argument

So your code as-is will start 3 different transactions (one for the main create / update op, and one each for your find ops). If you pass the req to your find operations, the find operations will re-use the existing transaction.

Try that?

from payload.

lekterable avatar lekterable commented on September 26, 2024

Are you setting max connections or anything like that?

Not explicitly, I'm using the default settings which Railway provides. I only copied the DB_URL

So your code as-is will start 3 different transactions (one for the main create / update op, and one each for your find ops). If you pass the req to your find operations, the find operations will re-use the existing transaction.

Try that?

Thanks for the tip! I think I'll just stick to Mongo as it seems to be more matured and doesn't cause any issues, but I'll try to provide a full repro when I have a minute.

from payload.

jmikrut avatar jmikrut commented on September 26, 2024

Of course.

It's worth noting that MongoDB would have this same issue if you use MongoDB with replica sets (you need replica sets in order to get MongoDB to work with transactions).

This would explain why in MongoDB, you do not see any issues (you probably don't have replica sets, so transactions are not enabled).

This whole transactions topic is a database-wide paradigm, in that transactions operate by reserving a connection for a specific transaction. Doesn't matter if it's Postgres or MongoDB - both work the same way when enabled.

I do think that for most use cases, Payload lends itself well to MongoDB though. So if you can switch, I wouldn't stop ya!

If you do get around to getting a repro put together, please post it here and I will re-open the issue.

Thank you!

from payload.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.