Hello, Not sure if this is the right channel but:...
# orm-help
s
Hello, Not sure if this is the right channel but: We're seeing a very weird behaviour with upsert (v3.0.2 of @prisma/client) and I'm wondering if someone here can provide some pointers.
When we execute an upsert on a single mysql 5.7 server, everything works fine: When record doesn't exist:
Copy code
xss_app                                | prisma:query BEGIN
xss_app                                | prisma:query SELECT fooId, barId FROM bazTable WHERE (`fooId` = ? AND `barId` = ?)
xss_app                                | prisma:query INSERT INTO `bazTable` (`fooId`,`barId`,`bif, `bof`) VALUES (?,?,?,?)
xss_app                                | prisma:query SELECT * FROM bazTable WHERE (`fooId` = ? AND `barId` = ?) LIMIT 1 OFFSET 0
xss_app                                | prisma:query COMMIT
When record exists:
Copy code
xss_app                                | prisma:query BEGIN
xss_app                                | prisma:query SELECT fooId, barId FROM bazTable WHERE (`fooId` = ? AND `barId` = ?)
xss_app                                | prisma:query UPDATE `bazTable` SET `fooId` = ?, `barId` = ?, `bif` = ?, `bof` = ? WHERE (`fooId`,`barId`) IN ((?,?))
xss_app                                | prisma:query SELECT * FROM bazTable WHERE (`fooId` = ? AND `barId` = ?) LIMIT 1 OFFSET 0
xss_app                                | prisma:query COMMIT
However, when we execute the same upsert against a mysql 5.7 master/slave cluster then we are seeing the following: When upsert works:
Copy code
[MASTER] xss_app                                | prisma:query BEGIN
[MASTER] xss_app                                | prisma:query SELECT fooId, barId FROM bazTable WHERE (`fooId` = ? AND `barId` = ?)
[MASTER] xss_app                                | prisma:query INSERT INTO `bazTable` (`fooId`,`barId`,`bif, `bof`) VALUES (?,?,?,?)
[MASTER] xss_app                                | prisma:query SELECT * FROM bazTable WHERE (`fooId` = ? AND `barId` = ?) LIMIT 1 OFFSET 0
[MASTER] xss_app                                | prisma:query COMMIT
When upsert fails:
Copy code
[MASTER] xss_app                                | prisma:query BEGIN
[MASTER] xss_app                                | prisma:query SELECT fooId, barId FROM bazTable WHERE (`fooId` = ? AND `barId` = ?)
[MASTER] xss_app                                | prisma:query INSERT INTO `bazTable` (`fooId`,`barId`,`bif, `bof`) VALUES (?,?,?,?)
[SLAVE] xss_app                                 | prisma:query SELECT * FROM bazTable WHERE (`fooId` = ? AND `barId` = ?) LIMIT 1 OFFSET 0
[MASTER] xss_app                                | prisma:query ROLLBACK
(and the following error:
prisma:client:fetcher Error: Query upsertOneBazTable is required to return data, but found no record(s).
)
This has us stumped since we assume that the totality of the queries of the upsert are executed in a single transaction (all writes go to the write master)
r
@Saimon Moore 👋 This looks like a bug. It would be great if you could open an issue here with the reproduction steps so that we can look into this 🙂
s
ok will do.
👍 1
@Ryan damn, we tried to workaround the upsert by doing a findOne, create, findOne but the create is also doing a select after the insert and we're running into the exact same problem 😞
Oooh I just found this: https://github.com/prisma/prisma/issues/5866 I wonder if this is related
r
Are you using RDS proxy?