SAP-samples/cloud-cap-samples

openSAP-week2-unit4567: POST request in orders.http fails

pandayo opened this issue · 3 comments

I issue this as an issue as one is advised to checkout the branch from here when taking the course yet the branch is not working as intended.

When running the following:

POST http://localhost:4004/browse/Orders
Content-Type: application/json

{ "OrderNo":"2019-09...", "Items":[
    { "book_ID":201, "amount":5 },
    { "book_ID":207, "amount":3 }
]}

I receive this stacktrace:
Error stacktrace: Error: Cannot build SQL. Invalid CQN object provided: undefined, ()=> orderItems.map (item => UPDATE (Books) .set ('stock -=', item.amount) .where ('ID =', item.book_ID) .and ('stock >=', item.amount) ) at build (/home/user/.node_modules_global/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds-runtime/lib/db/sql-builder/sqlFactory.js:89:9) at executeGenericCQN (/home/user/.node_modules_global/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds-runtime/lib/sqlite/execute.js:222:32) at SQLiteDatabase._run (/home/user/.node_modules_global/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds-runtime/lib/db/query/run.js:24:10) at SQLiteDatabase. (/home/user/.node_modules_global/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds-runtime/lib/sqlite/Service.js:139:19) at next (/home/user/.node_modules_global/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds/lib/srv/Service.js:109:26) at SQLiteDatabase.dispatch (/home/user/.node_modules_global/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds/lib/srv/Service.js

Maybe this should be fixed for future participants of the openSAP course on "Building Applications with SAP Cloud Application Programming Model"

chgeo commented

Thanks for reaching out. Will take a look when we update the course materials.

Please note that we are about to close this issue channel in favor of the our community.

@chgeo that might be unfortunate--the search capabilities in the Community site are quite inferior to GitHub, and I could not find anything on Community site with search string "Cannot build SQL. Invalid CQN object provided: undefined". I encountered the same issue reported above.

GET /admin/Orders?&$expand=Items
POST /browse/Orders
[2020-11-25T18:06:34.105Z | ERROR | 1609633]: Error: Cannot build SQL. Invalid CQN object provided: undefined
    at build (/home/user/projects/cloud-cap-samples/node_modules/@sap/cds-runtime/lib/db/sql-builder/sqlFactory.js:90:9)
    at executeGenericCQN (/home/user/projects/cloud-cap-samples/node_modules/@sap/cds-runtime/lib/sqlite/execute.js:249:32)
    at SQLiteDatabase._run (/home/user/projects/cloud-cap-samples/node_modules/@sap/cds-runtime/lib/db/query/run.js:24:10)
    at SQLiteDatabase.<anonymous> (/home/user/projects/cloud-cap-samples/node_modules/@sap/cds-runtime/lib/sqlite/Service.js:137:19)
    at next (/home/user/projects/cloud-cap-samples/node_modules/@sap/cds/lib/srv/Service.js:87:30)
    at SQLiteDatabase.dispatch (/home/user/projects/cloud-cap-samples/node_modules/@sap/cds/lib/srv/Service.js:93:8)

Hi Everyone,

I have encountered the same issue - result is as below - Can someone explain the issue or solution towards it (i am new to this whole CAP and JS, coming from ABAP background)

[cds] - POST /browse/Orders
[cds] - { Error: Cannot build SQL. Invalid CQN object provided: undefined
at build (/local/npm/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds-runtime/lib/db/sql-builder/sqlFactory.js:90:9)
at executeGenericCQN (/local/npm/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds-runtime/lib/sqlite/execute.js:269:27)
at SQLiteDatabase._run (/local/npm/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds-runtime/lib/db/query/run.js:24:10)
at SQLiteDatabase. (/local/npm/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds-runtime/lib/sqlite/Service.js:108:19)
at next (/local/npm/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds/lib/srv/Service-dispatch.js:56:36)
at SQLiteDatabase.dispatch (/local/npm/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds/lib/srv/Service-dispatch.js:62:11) id: '1395505', level: 'ERROR', timestamp: 1619659122331 }