cancel
Showing results for 
Search instead for 
Did you mean: 

Updated to CDS 7, the PATCH event was changed from "UPDATE" to "CREATE"?

JWJ
Participant

We are trying to update our project from CDS 6 to CDS 7.

All our unit tests that use the PATCH request method are failing with "entity already exists" and I found that the `req.event` has changed from UPDATE to CREATE.

Our 'UPDATE' handlers are no longer getting triggered after updating to CDS 7.

I'm wondering if it is a misunderstanding on my part of what a PATCH should do or if this is a bug introduced in CDS 7 that needs to be reported?

Previous `cds v` output before cds update:

@sap/cds: 6.7.0
@sap/cds-compiler: 3.8.2
@sap/cds-dk (global): 6.7.0
@sap/cds-fiori: 1.0.0      
@sap/cds-foss: 4.0.0       
@sap/cds-mtxs: 1.7.0
@sap/eslint-plugin-cds: 2.6.3
Node.js: v16.18.0

After updating cds:

@sap/cds: 7.0.2
@sap/cds-compiler: 3.9.4   
@sap/cds-dk (global): 7.0.1
@sap/cds-fiori: 1.0.0      
@sap/cds-foss: 4.0.2       
@sap/cds-mtxs: 1.9.0
@sap/eslint-plugin-cds: 2.6.3
Node.js: v18.16.1

Accepted Solutions (1)

Accepted Solutions (1)

JWJ
Participant

I'm not 100% sure what I did to fix it but I believe it had to do with the `@restrict` annotation on the same entity where PATCH was being applied.

I started making other changes to bring things up to the new CDS 7 standard and that includes fixing the `@restrict` applied to the same entity where PATCH tests were broken.

So now it is triggering the "UPDATE" handler again and all my tests are passing. Not sure why it was going straight to "CREATE" before I updated the `@restrict`. It possibly does a READ first (although I didn't see READ get triggered either) and due to the broken `@restrict` it was getting nothing back and therefor applied CREATE instead of UPDATE.

vansyckel
Advisor
Advisor
0 Kudos

Hi Jay,

FYI, It tries to do an UPDATE first. If this results in a not found error, which is the case if the @restrict clause prevents the update (the user shall not be able to find out if the entity exists), then it tries the CREATE. You do not see the UPDATE event because it is rejected before it reaches your handlers.

Best,
Sebastian

Answers (0)