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

CAP insertable service error with DB defaults #25

Open
dvvelzen opened this issue Jan 15, 2020 · 3 comments
Open

CAP insertable service error with DB defaults #25

dvvelzen opened this issue Jan 15, 2020 · 3 comments

Comments

@dvvelzen
Copy link

dvvelzen commented Jan 15, 2020

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
Copy link
Contributor

vobu commented Jan 15, 2020

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
Copy link
Author

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
Copy link
Author

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

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

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

2 participants