cancel
Showing results for 
Search instead for 
Did you mean: 

Error "An error occurred during serialization of the entity collection" with deep navigation

SamueleBarzaghi
Participant
0 Kudos

Hi,

We get the error:

An error occurred during serialization of the entity collection.  
An error occurred during serialization of the entity with the following key(s): ID: 7aa24fe3-6a4b-4f6c-bb89-de29c3251990, IsActiveEntity: true.  
Not nullable value for 'ID' must not be null.

Screenrecoding (bad screenrecording but I think is enough)

https://github.com/sbarzaghialteaup/serialization_error/blob/master/explain_problem.gif

Repository with a project to reproduce:

https://github.com/sbarzaghialteaup/serialization_error

The odata request is:

GET Books?$count=true&$filter=(IsActiveEntity%20eq%20false%20or%20SiblingEntity/IsActiveEntity%20eq%20null)&$select=HasActiveEntity,ID,IsActiveEntity,title&$expand=author($select=ID,IsActiveEntity,name;$expand=city($select=ID,citizenCount,name))

Thanks for support

Sam

Accepted Solutions (0)

Answers (1)

Answers (1)

vobu
Active Contributor
0 Kudos

the query indicates an expand from books -> author

and looking at your dataset, the books.csv file is mssing a value in the authors_id column for the book id mentioned in the error msg.

if you provide that value, all should be fine.

SamueleBarzaghi
Participant
0 Kudos

Hi Volker,

Thank you for your support.

I know the problem is the missing ID of the author, but the author is not a mandatory field so the csv reproduce a real situation (you can also reproduce it deleting the csv and creating manually a new book without the author with the fiori app).

Further why is the behaviour not consistent between dev and production? In production we don't have the problem, strange

Thanks

Sam

vobu
Active Contributor
0 Kudos

looking at your model definition, your're using a managed scenario:

using {cuid} from '@sap/cds/common';
//...
entity Books : cuid {
    // ...
    author : Association to one Authors;
}


@cds.odata.valuelist
entity Authors : cuid {
    // ...
}

and `cuid` is defined as

aspect cuid {
  key ID : UUID; //> automatically filled in
}

resulting in the ref constraint of non-empty IDs.

The model translates to me as "there are many books and every book has exactly one author".

So if you provide sample data, there needs to be 1 author for each book.

The reason you're not getting the error in prod might be due to the fact that you don't provide initial sample data to the app (as you do in dev via /db/data/**/*)

htht, v.

SamueleBarzaghi
Participant
0 Kudos

Hi Volker,

Very good question, "association to one" is "1:1" or "1:0..1"? I cannot find the answer in the documentation.

I provide sample data in production too, for production I mean environment with NODE_ENV set to "production".

Offtopic: I think call it sample data is misleading, these are very very very dangerous initial data deployed in production too, if not correctly used the risk is to loose production data, I hope this functionality will be review today 😉

https://github.com/SAP-samples/cloud-cap-samples/issues/47

Thanks

Sam