Skip to Content
Sep 29, 2021 at 09:17 AM

$count on an entity with no data results in 500 Internal Server Error

371 Views Last edit Sep 29, 2021 at 09:41 AM 3 rev


I am working on Cloud Application Programming Model with NodeJS. I have a schema model with some simple entities. I am trying to get the number of rows in the entity using $count.

The above behavior works when there is data present in the entity. When there are no rows in the entity like:

In this case if I do the $count like mentioned above, i get the 500 Internal Server Error saying Invalid Etag value.

I expected to get 0 or a null value but instead getting Internal Server Error. I have etags enabled but GET calls don't even need etag values in header.
Also, the screenshots are from local sqlite run,but in the HANA database as well, the same behavior is observed. Please guide on why this is happening and what should be done to correct this.

After some research, I want to point out one thing that this error only comes up in the entities where etag is enabled, elsewhere the $count works correctly resulting 0 in case of no data.
Here is the entity definition with etag annotation:

entity MarketPartner : managed {
    key mpID         : types.mpID;
        //Association to GenActivation ( managed to-Many )
        activation   : Composition of many GenActivation
                           on activation.mpID = $self;

        name         : not null;
        comments     : types.comments;
        obsoleteFlag : types.obsoleteFlag default false;
        createdAt    : types.createdAt  @cds.on.insert : $now;
        createdBy    : types.createdBy  @cds.on.insert : $user;
        modifiedAt   : types.modifiedAt @cds.on.insert : $now  @cds.on.update  : $now  @odata.etag;
        modifiedBy   : types.modifiedBy @cds.on.insert : $user  @cds.on.update : $user;