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

Change tracking not recorded when inserting multiple records #145

Open
talmeidanewsuk opened this issue Feb 4, 2025 · 0 comments
Open

Comments

@talmeidanewsuk
Copy link

talmeidanewsuk commented Feb 4, 2025

Hi,

Project code to replicate the issue

On our project we have an action that has the following insert statement:

module.exports = cds.service.impl(async function (srv) {
  const { MyEntity } = this.entities;
  /// ...
  function createRecords() {
    const result = await INSERT.into(MyEntity).entries(arrayOfObjects);

We have noticed that when the arrayOfObjects has 1 element, the change tracking records are recorded for that element (as expected) but when the array has >1 records, no change tracking is recorded. No other changes to the code. We even debugged the plugin and noticed it gets undefineds when comparing old and new records. Please see below a screenshot from debugging our original project:

Image

I noticed a similar issue report from last year which was closed due to the lack of sample code. here:

I tried to replicate on a sample project but ran into another issue.

Steps I've taken to replicate on sample project

I have taken the sample incidents project and implemented 4 actions createSingle, createMultiple1,2,3.

  • createSingle uses CQL to create a single record and works as expected - change log entries recorded.

  • createMultiple2,3 uses CQL to create multiple records in one go. These actions don't work as expected as they don't insert. But, according to CAP docs they shoud as it says INSERT can be passed to srv or db objects and that the call to entries() can have 1 or more entries. This was unexpected and maybe another issue in CAP itself. When calling createMultiple2,3 we get an exception.

  • createMultiple4 works as expected (creates record and change logs) but is extremely slow if you have 1000s of records as it does multiple single inserts per record which in our real work scenario takes too long and is why we moved to a version that does the inserts with a statement like this one: await INSERT.into(MyEntity).entries(arrayOfObjects) but then runs into the problem that no changelog records are created.

Project code to replicate the issue

versions

We are using CAP 8 and latest change-tracking 1.0.7

Thank you in advance

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

1 participant