Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App reports Error when change tracking enabled for Entities with a key field not named ID #49

Open
dinurp opened this issue Nov 29, 2023 · 4 comments
Assignees

Comments

@dinurp
Copy link

dinurp commented Nov 29, 2023

I generated a sample application using cds add samples.
I renamed the field ID of Books to BookID in db/schema.cds and updated test data too.

entity Books : managed {
  key BookID : Integer;
  @mandatory title  : localized String(111);
  descr  : localized String(1111);
  @mandatory author : Association to Authors;
  genre  : Association to Genres;
  stock  : Integer;
  price  : Decimal;
  currency : Currency;
  image : LargeBinary @Core.MediaType : 'image/png';
}

I enabled change tracking for the entity Books of AdminService with annotations:

annotate AdminService.Books with @changelog : [BookID] {
	title @changelog;
	descr @changelog;	
	price @changelog;
	currency @changelog;	
	stock @changelog;
}

Now when I try to change the title of Book with title "Catweazle" using fiori preview for Books entity, the application reports error.: Error: "ID" not found in the elements of "AdminService.Books"

I see in the console the following error.

odata] - POST /odata/v4/admin/$batch 
[odata] - > PATCH Books(BookID=271,IsActiveEntity=false) 
[odata] - > draftPrepare Books(BookID=271,IsActiveEntity=false)/AdminService.draftPrepare 
[odata] - > draftActivate Books(BookID=271,IsActiveEntity=false)/AdminService.draftActivate {
  '$select': 'BookID,HasActiveEntity,HasDraftEntity,IsActiveEntity,author_AuthorID,createdAt,createdBy,currency_code,descr,genre_code,modifiedAt,modifiedBy,price,stock,title',
  '$expand': 'DraftAdministrativeData($select=DraftIsCreatedByMe,DraftUUID,InProcessByUser),author($select=ID,name),genre($select=ID,name)'
}
[cds] - Error: "ID" not found in the elements of "AdminService.Books"
    at stepNotFoundInCombinedElements (D:\book-shop\node_modules\@cap-js\db-service\lib\infer\index.js:807:15)
    at D:\book-shop\node_modules\@cap-js\db-service\lib\infer\index.js:543:13
    at Array.forEach (<anonymous>)
    at inferQueryElement (D:\book-shop\node_modules\@cap-js\db-service\lib\infer\index.js:489:18)
    at processToken (D:\book-shop\node_modules\@cap-js\db-service\lib\infer\index.js:371:11)
    at Array.forEach (<anonymous>)
    at walkTokenStream (D:\book-shop\node_modules\@cap-js\db-service\lib\infer\index.js:375:19)
    at inferQueryElements (D:\book-shop\node_modules\@cap-js\db-service\lib\infer\index.js:344:16)
    at infer (D:\book-shop\node_modules\@cap-js\db-service\lib\infer\index.js:69:22)
    at cqn4sql (D:\book-shop\node_modules\@cap-js\db-service\lib\cqn4sql.js:47:20) {
  id: '1344032',
  level: 'ERROR',
  timestamp: 1701262020937
}

There were no issues before I renamed the field.

@nkaputnik
Copy link
Contributor

Hi @dinurp
this is not a bug or issue with Change-Tracking, this is a limitation of Fiori Draft.
Draft-Enabling an entity requires the entity to have a GUUID based ID, so this error message has nothing to do with the Plug-in.

Best,
Nick

@dinurp
Copy link
Author

dinurp commented Dec 6, 2023

Hi Nick,
The issue remains even when the type of the field is changed to UUID. Fiori draft does not mandate that the keys are named ID. For localized entities, the generated key is named ID_texts. It is not evident in the stack trace. But, the query that causes the crash is from change tracking.
BTW: The type Integer was in the generated sample with cds add samples and it works just fine when change tracking is not used.
Regards,
Dinu

@nkaputnik
Copy link
Contributor

Hello @dinurp
we will look into this. In the meantime, since this is an open source project: If you can debug your project and pinpoint to specific pieces of the plug-in code, this would be a huge help for us.

Best,
Nick

@nkaputnik nkaputnik self-assigned this Dec 11, 2023
@dinurp
Copy link
Author

dinurp commented Dec 11, 2023

Dear Nick,
Here is the fix that worked for me. It may not cover all the cases, but solved the I issue I faced.
diff-support-naming-keyfield.txt
Regards,
Dinu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants