05-10-2024 2:37 PM - edited 05-10-2024 2:43 PM
Dear experts,
We are facing a problem since a couple of weeks in a service that has been running for almost two years now:
We have two services connected via CDS import where I'm exposing one entity to be used locally from the other service:
@readonly
entity Divisions as projection on MD.Divisions;
Then I'm doing a basic selection:
const division = await this.run(SELECT.one.from(this.entities.Divisions)
.where({ division: t.division_division }));
When the framework expand the selection to build the query changes the * by a list of fields that come from the following structure in the cds.entities.Divisions.elements:
The two highlighted properties are the foreign keys of the automatic association localized. They do not belong to the Divisions entity and I have no idea why they are there.
We have a four systems landscape and we are facing this error in two of the system, I aligned package versions and the problem cannot be reproduced:
I checked for errors in the EDMX file we used on the cds import or in the csn.json file that points to these properties without success.
Can anyone support here?
Thanks,
Juanjo
@patricebender I have created a demo project in this repository.
To reproduce the specific architecture of my case I have added two separated cap services:
MasterData contains entity division which is a CodeList that contains attributes name and descr that are localized. As we plan to maintain the translations with a UI app we manually expose the entities in the service:
using {MasterDataDb as MD} from '../db/MasterData';
@(path: '/MasterData')
service MasterData {
entity Divisions as select from MD.Divisions;
entity Divisions_texts as projection on MD.Divisions.texts;
}
MasterData service should be launched on port 4007 with:
cds w --port 4007
You can access locally to both the Divisions and their texts:
http://localhost:4007/MasterData/Divisions | http://localhost:4007/MasterData/Divisions('1')/texts |
|
|
On the BusinessPartner service we included the Divisions as external entity to allow the association:
using {
cuid,
managed
} from '@sap/cds/common';
namespace BusinessPartnerDb;
using { MasterData as MD } from '../srv/external/MasterData';
entity BusinessPartners : cuid, managed {
name: String;
division : Association to one MD.Divisions;
}
@readonly entity Divisions as projection on MD.Divisions;
@readonly entity Divisions.texts as projection on MD.Divisions_texts;
Pleas note that the maintenance will be done directly on the MD service so on the BP we expose the entities as readonly.
As the expand to an external service is not directly executed by CAP we implemented the ON event handler for the read operation:
module.exports = cds.service.impl(async function businessPartnerService() {
/**
* External entities read for masterData service
*/
this.on('READ', 'Divisions', async (req) => {
// Instance the external service
const md = await cds.connect.to('MasterData');
// Execute the query
return md.run(req.query);
});
});
If you trigger the BusinessPartner service with:
cds w --port 4004
And then try to open the Divisions entity from the BP service you will get the error I'm reporting:
As I mentioned earlier, the project has been working fine with this architecture for almost 2 years, and only recently we have started receiving this error, so we think the reason could be related to a package upgrade. We have two system where it's working right now and two systems where it's crashing.
Thank you for support.
Kind regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
11 | |
8 | |
8 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.