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

"Update" change logs are not created in the main test system #84

Open
032660 opened this issue Apr 17, 2024 · 2 comments
Open

"Update" change logs are not created in the main test system #84

032660 opened this issue Apr 17, 2024 · 2 comments

Comments

@032660
Copy link

032660 commented Apr 17, 2024

Hi colleagues,

We are working on the project https://github.tools.sap/erp4sme/crypto-for-business.

Some time ago we have discussed missing possibility to add changelog changes for an entity that is being processed not from a service (for example, UI service) but is inserted or updated directly on DB.

Meanwhile this issue was solved: we created Wrapper-Services for the involved entities and this solved even the second issue where a view was defined as a union of three different entities and we were not sure how to define change tracking for this.

It looks like (srv\payment\wrapper\wrapper-service.cds):

service PaymentWrapperService @(requires: 'system-user') {
entity Payments as projection on db.payments.Payments;
entity Payables as projection on db.payables.Payables;
entity PaymentOrders as projection on db.paymentOrders.PaymentOrders;
entity Receivables as projection on db.receivables.Receivables;
entity BusinessTransactions as projection on db.businessTransactions.BusinessTransactions;
}

BusinessTransactions is the mentioned view which is a union of Payments, Receivables and Payables.

Now all our DB operations relevant for change-tracking are defined via this service, for example

UPDATE.entity(WrapperService.Entity.Payments).where({ ID: paymentToUpdate.ID }).with(paymentToUpdate);

This works; the changes for all involved entities are written back and shown in the app “business Transactions” based on an UI service defined on the entityBusinessTransactions.

However there is one strange thing.

For creating the entities change logs are written both if you test locally or in the main test system https://c4b-main02-subscriber-1.c4b-main02.dev01.eu.canary.clusters.cs.services.sap/.
However these entities can be also updated. This is happening not from UI but from an Event Handler reacting on some events. For example if a Transfer Order which was created for a Payment becomes completed then the corresponding Payment gets status “Completed” as well. The event is thrown during a job run. Updating the Payment is fulfilled via WrapperService in lib\payment\payments\DbPaymentRepository.ts.

Now if I am testing this event processing locally then I see that the changes with modification = “update” are inserted into CHANGELOG and CHANGES. Unfortunately I cannot execute the mentioned job (it is running only in MAIN system). But I tested this from a unit test firing the same event and the update changes were created.

When the job is running in MAIN and payments are updated with the new status “Completed” it is however not reflected in CHANGELOG and CHANGES.

Do you have any idea what can be the difference? We supposed that this was due to the job execution. But we have other events which are creating new instances of Payment – and this works; the “create” changes are created.

What in MAIN environment could inhibit creating “update” change logs?

Kind regards,
Elena Gurevich

@032660 032660 changed the title "Updated" change logs are not created in the main test system "Update" change logs are not created in the main test system Apr 17, 2024
@032660
Copy link
Author

032660 commented Apr 18, 2024

Hi colleagues,

I executed some tests and checked created entities. Could you please confirm that an "update" modification creates a change log only if "modifiedAt" or "modifiedBy" has changed after this update?

I suppose that it is so because there is:

// Since req.diff() will record the managed data, change history will filter those logs only be changed managed data
const managedAttrs = ["modifiedAt", "modifiedBy"]
if (curChange.modification === "update") {
const rowOldAttrs = Object.keys(childNodeChange._old)
const diffAttrs = rowOldAttrs.filter((attr) => managedAttrs.indexOf(attr) === -1)
if (!diffAttrs.length) {
return
}
}

If I am right then you can close this issue because I found out that neither modifiedAt nor modifiedBy was changed for the entities for which update change log is missing.

Kind regards,
Elena

@032660
Copy link
Author

032660 commented Apr 19, 2024

Hi colleagues,

I enforced modifiedAt to be changed at updating. However I still do not see any changelogs.

Is it necessary to change also modifiedBy?

Or am I wrong when I suppose that "modified" fields can affect creating changelogs?

Kind regards,
Elena

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