sapmentors / cap-community

SAP CAP Community
MIT License
97 stars 26 forks source link

CAP insertable service error with DB defaults #25

Open dvvelzen opened 4 years ago

dvvelzen commented 4 years ago

Hi,

I've created a new cds project with cds init and created a db/ and srv/ service.

The db service is using a not null field with a default. The service is a projection with with Capabilities annotation;

db/

entity Test { 
  key ID : UUID; 
  VAL: Integer default 12 not null 
}

srv/

@Capabilities: { Insertable: true, Updatable: false, Deletable:false }
entity Test as projection on my.Test; 

When doing a POST to create a new entry with only the ID field supplied I get the following error:

{
 "error": {
 "code": null,
 "message": "An error occurred during serialization of the entity. Not nullable value for 'VAL' must not be null."
 }
}

The insert did work though as it is in the database. Secondly if I set Updatable to true the service works normally and returns the created entity without an error.

/D

vobu commented 4 years ago

hi, i'm guessing that you would expect the POST to either not work at all (incl persistence) or work with a warning (given that you set a default value for VAL). right? but -without any pun intended- i don't fully get VAL: Integer default 12 not null b/c i'd rather expect VAL: Integer not null or VAL: Integer default 12 why both default and not null?

dvvelzen commented 4 years ago

Hi,

I would expect the Insertable (POST) to work by sending "ID" only and getting a return of "ID" and "VAL". "VAL" having the value of the default as it is not supplied.

If I do the above INSERT. With Updatable: true => this works ok. If I do the above INSERT. With Updatable: false => this enters a records in DB, but throws an error on the service.

HTH, Dennis

dvvelzen commented 4 years ago

Seems to be picked up based on the initial question on the community page;

https://answers.sap.com/answers/12950237/view.html