-
Notifications
You must be signed in to change notification settings - Fork 15
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
cds init change-tracking-bugcd change-tracking-bugnpm add @cap-js/change-trackingnpm itouch db/schema.cdsAdd the following content todb/schema.cds:
namespace my.bookshop;
entity Books {
key NOT_ID : Int16;
@changelog
title : String;
}touch srv/api.cdsAdd the following content tosrv/api.cds:
using { my.bookshop as shop } from '../db/schema';
Service CatalogService {
entity Books as projection on shop.Books;
}touch test/CatalogService.httpAdd the following content totest/CatalogService.http:
@server=http://localhost:4004
@username=alice
@password=
### Books
# @name Books_POST
PUT {{server}}/odata/v4/catalog/Books(NOT_ID='42')
Content-Type: application/json
Authorization: Basic {{username}}:{{password}}
{
"title": "title-4711"
}
cds watchand then fire the request intest/CatalogService.http- Observe the error:
[error] - 500 - Error: "ID" not found in the elements of "CatalogService.Books"
at stepNotFoundInCombinedElements (/Users/patricebender/SAPDevelop/change-tracking-bug/node_modules/@cap-js/db-service/lib/infer/index.js:794:13)
at /Users/patricebender/SAPDevelop/change-tracking-bug/node_modules/@cap-js/db-service/lib/infer/index.js:501:11
at Array.forEach (<anonymous>)
at inferArg (/Users/patricebender/SAPDevelop/change-tracking-bug/node_modules/@cap-js/db-service/lib/infer/index.js:441:13)
at processToken (/Users/patricebender/SAPDevelop/change-tracking-bug/node_modules/@cap-js/db-service/lib/infer/index.js:307:11)
at Array.forEach (<anonymous>)
at walkTokenStream (/Users/patricebender/SAPDevelop/change-tracking-bug/node_modules/@cap-js/db-service/lib/infer/index.js:311:19)
at inferQueryElements (/Users/patricebender/SAPDevelop/change-tracking-bug/node_modules/@cap-js/db-service/lib/infer/index.js:280:16)
at infer (/Users/patricebender/SAPDevelop/change-tracking-bug/node_modules/@cap-js/db-service/lib/infer/index.js:71:22)
at cqn4sql (/Users/patricebender/SAPDevelop/change-tracking-bug/node_modules/@cap-js/db-service/lib/cqn4sql.js:77:14) {
code: ''
}- The issue is that the change-tracking logic expects an
IDfield by default, but the entity uses a different key field name (NOT_ID). This results in the error when trying to process the request.
Here is the loc which generates the faulty query:
const getCurObjFromDbQuery = async function (entityName, queryVal, /**optional*/ queryKey='ID') {
if (!queryVal) return {}
// REVISIT: This always reads all elements -> should read required ones only!
const obj = await SELECT.one.from(entityName).where({[queryKey]: queryVal})
return obj || {}
}→ this is the invalid query which is send to the db-service (which is rightfully rejected):
{
"SELECT": {
"one": true,
"from": {
"ref": [
"CatalogService.Books"
]
},
"where": [
{
"ref": [
"ID" // ❌ There is no ID in Books
]
},
"=",
{
"val": "undefined" // ❌ this is also broken
}
],
"expand": "root"
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working