cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Serialization error on local started CAP server

former_member748
Participant
0 Likes
1,470

Hello,

I have defined the following entity and association in the data-model.cds:

entity A {
     key ID : types.AppKeyT; 
     key ORDER_NO : String(4); 
     VALUE : Boolean; 
     LINK : Association[1..1] to B on LINK.ID = VALUE; 
}
entity B { 
    key ID : types.TypeT;
    PATH : types.DescT; 
    NAME : types.DescT; 
}

The I have them defined in a service.cds:

entity A1 as projection on A;
entity B1 as projection on B;

For some rows in the table, VALUE will be null.

On the deployed app if I try to call /A?$expand=LINK I just see in the response "LINK: null", but in the app started from VSCode I get the following error:

Serialization Error for the entity with the following key(s): ID: 001, ORDER_NO: 10. Not nullable value for 'LINK' must not be null.

I've seen other serialization errors which happen only in the app started locally and not present in the one deployed.

In package.json I have requires.db.kind.hana and credentials in default-env.json.

Is it somehow using SQLite on local? Is anyone aware of any configuration that can be done to avoid serialization errors?

If I run cds env get requires I still see sql and sqlite:

  sql: {
    use: 'sqlite',
    credentials: { database: ':memory:' },
    impl: '@sap/cds-runtime/lib/sqlite/Service.js',
    kind: 'sqlite'
  },
  sqlite: {
    use: 'sqlite',
    credentials: { database: 'sqlite.db' },
    impl: '@sap/cds-runtime/lib/sqlite/Service.js'
  },

Is it expected that these env variables are like this?

Looking forward to finding out more info about this topic 🙂

Thank you,

Best regards,

Stefania

View Entire Topic
david_kunz2
Product and Topic Expert
Product and Topic Expert

Hi stefania-santimbrean,

Serialization errors only happen during development, it will be checked that the data you return are structurally correct. In your case, you define an association which must not be null, however, the data you provide apparently contains entries for A which have no LINK. In productive scenarios (aka NODE_ENV=production), this check is disabled.
To fix this: Provide correct data.

Best regards,
David

former_member748
Participant
0 Likes

Hello David,

Thanks for your quick response and explanation. I guess one way to fix the problem is running locally with NODE_ENV=production.

Any other way of disabling the check? In the case of these entities the association can be null (or we want it to be able to be null).

Best regards,

Stefania

david_kunz2
Product and Topic Expert
Product and Topic Expert

Hi stefania-santimbrean,

I think a better solution would be if you model your entity to also allow null associations:

entity A {
keyID: types.AppKeyT;
key ORDER_NO: String(4);
VALUE: Boolean; LINK :Association to B on LINK.ID=VALUE;
}

Best regards,
David