on 11-11-2023 10:27 AM
Hello CAP Team,
I've the following after UPDATE handler for Books:
srv.after("UPDATE", Books, async (req) => {
const db = await cds.connect.to("db");
const { Books: dbBooks } = db.entities;
console.log("After request update triggered");
await cds.tx(async (tx) => {
const data = {
title: "haha",
stock: 0,
};
// Expectation: Throws an error if entity can not be locked because it was updated in the standard handler
let exists = await SELECT(1).from(dbBooks, 11).forUpdate();
console.log("before updating book in separate tx");
const result = await tx.update(dbBooks, 11).with(data);
console.log("after updating book in separate tx");
});
});<br>
When I run the following request:
###
PUT http://localhost:4004/admin/Books(11)
Authorization: Basic admin:
Content-Type: application/json
{
"title": "test",
"stock":12
}
the execution gets stuck in the line with the SELECT for Update.
I would expect that the SELECT forUpdate should throw an exception when it can't get a lock. What do you think?
If you want to replicate this issue please check bookshop-demo. The code is in srv/admin-service.js#L185 and the REST Client test request in tests/app/admin.http#L116.
Best Regards
Gregor
Hi Gregor,
if not wait time is specified, the default of the database applies (see https://cap.cloud.sap/docs/node.js/cds-ql#forupdate). On SAP HANA, that's the lock_wait_timeout of the index server.
let exists = await SELECT(1).from(dbBooks, 11).forUpdate({wait: 2});
This would wait for 2 seconds until it throws an error.
Best,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just a reference also to the .forUpdate() documentation.
User | Count |
---|---|
83 | |
11 | |
10 | |
8 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.