pacificclimate / p2a-rule-engine

Climate impacts engine for Plan2Adapt.ca
0 stars 0 forks source link

PCEX API expects parameters to be strings #11

Open corviday opened 4 years ago

corviday commented 4 years ago

This is more of a warning than an issue, as we are intending to fix it in the API. It doesn't need a permanent fix in this repository, but it may need a temporary patch.

The climate explorer backend was originally developed as a web API. Accordingly, functions would receive all their arguments as strings, since the URL which called them provided them as strings. The backend sometimes checks whether a specific parameter has been provided using

if parameter:
  # do a calculation with the parameter
else:
  # do a calculation without the parameter

This construction worked when parameters are strings but fails in the case of a numeric parameter whose value is zero being supplied as an int 0 instead of a string "0" - the parameter-checking if will conclude the int parameter was not supplied at all because 0 is falsy.

If you need to run the rules engine before the PCEX API has been fixed, you can get around this issue by casting this int to a string.

corviday commented 4 years ago

This branch records the temporary solutions to this issue and #10 .