mobilityhouse / ocpp

Python implementation of the Open Charge Point Protocol (OCPP).
MIT License
766 stars 298 forks source link

Bug in parsing floats in Payloads that yields the failure of sending 5 Messages #555

Open AlfredoNaef opened 8 months ago

AlfredoNaef commented 8 months ago

Hello,

The messages NotifyChargingLimitRequest, NotifyMonitoringReportRequest, ReportChargingProfilesRequest, RequestStartTransactionRequest and SetChargingProfileRequest fail to be validated and hence to be sent. The bug happen when in all these messages payloads is present a float. Specifcally :

Aftre reading the comment inside your code to my understanding the problem is due to the parser used to parse the floats in the payloads, that a default is float(). Indeed, you left a comment specifying that for some schemas should be used decimal.Decimal. However, as an user of your library I can only access your code up to the call method of your ChargePoint class and there is no possibility for me to sepcify the parser inside call - validate_payload - get_validator. Do you think that adding the possibility to specify the parse_float at the call method will fix the issue or is there another problem with the parsing of the floats?

OrangeTux commented 7 months ago

Thanks for your elaborate report.

I'm curious why validation fails, though. The schemas for OCPP 1.6 limit the decimal points of a few number types to 1. It does so using the JSON Schema keyword multipleOf. See for example the subschema for ChargingSchedulePeriod.limit.

You noticed correctly that this library includes a custom encoder to serialize these floats. See for example here and here.

The schemas of OCPP 2.0.1 don't use the multipleOf JSON keyword. Therefore, I don't understand how you run into validation issues. Can you provide a code example shows the validation issue?

Jared-Newell-Mobility commented 7 months ago

To confirm the types highlighted in the issue are floats in the library - changing to question