cancel
Showing results for 
Search instead for 
Did you mean: 

CAP's Decimal type's scale not validated

jerinjacob
Explorer
0 Kudos

Hi Experts,

I found that CAP's built in type Decimal(precision, scale) does not validate `Scale`/`Precision` properly.

When inserting to an entity having decimal like:

entity Book : cuid {
    price : Decimal(5, 2);
}<br>

with value

  • {price: 13.042} => gets accepted and inserted
  • {price: 1300.4} => gets accepted and inserted
  • {price: 1.034} => gets accepted and inserted
  • {price: 1.0034} => gets accepted and inserted
  • {price: 13.4122} => Error 400 {"message": "Deserialization Error: Invalid value 13.4122 (JavaScript number). The specified Edm.Decimal value does not correspond to the Precision facet value (5)."}
  • {price: 13000.4} => Error 400 {"message": "Deserialization Error: Invalid value 13000.4 (JavaScript number). The specified Edm.Decimal value does not correspond to the Precision facet value (5)."}
  • {price: 1.334} => Error 400 {"message": "Deserialization Error: Invalid value 1.334 (JavaScript number). The specified Edm.Decimal value has more digits to the right of the decimal point than allowed by the Scale facet value (2)."}

Any advice gladly accepted.

Regards,

Jerin Jacob

Accepted Solutions (0)

Answers (1)

Answers (1)

vansyckel
Advisor
Advisor
0 Kudos

Hi Jerin,

Thanks for reporting. I can reproduce and we will have a look.

One remark: SQLite is famously lax in such regards. On HANA, 13.042, for example, would become 13.04 (i.e., the additional digits are pruned) and 1300.4 results in an error.

Best,
Sebastian

jerinjacob
Explorer

Hi Sebastian,

Thanks for confirming that.

I found this issue in a BTP Prod subaccount where CAP server is connected to SAP Hana Cloud. When attempting to push the value `1300.00`, it responded back with

 `"message": "numeric overflow: Failed in \"PRICE\" column with the value 1300.00"` 

which originated from Hana Cloud. I believe CAP can and should validate this input before sending it to Hana.

Thanks for letting me know of SQLite's limitations.

Regards,

Jerin Jacob

jerinjacob
Explorer
0 Kudos

Hi Sebastian,

Is there any way I can track the progress of the issue?

What would be the estimated time required for this issue to be resolved in a new CAP NPM release?

Thanks,

Jerin Jacob

vansyckel
Advisor
Advisor

Hi Jerin,

We do not have external tracking, I'm afraid. But the feature will be part of the next release.

Best,
Sebastian