astarte-platform / astarte

Core Astarte Repository
https://docs.astarte-platform.org/
Apache License 2.0
236 stars 45 forks source link

`longinteger` values cannot receive a string input in server-owned interfaces #967

Open rbino opened 3 weeks ago

rbino commented 3 weeks ago

longinteger values are exposed as strings by default by AppEngine API since they are 64 bit integers and JSON is only able to represent ~53 bit integers at most since all numbers are double.

This means that we should also accept integer values as input (since they are the only way to send longinteger values bigger than 53 bits with a JSON), but we currently don't.

Sketch of the fix

Add another clause to cast_value here which more or less does this:

  defp cast_value(:longinteger, string_value) when is_binary(string_value) do
    # Try to parse the value as integer, return `{:ok, int_value}` or `{:error, :unexpected_value_type}`
  end

  defp cast_value(:longintegerarray, string_values) do
    # Similar but for an array of values. Map over them and return an `{:ok, list_of_ints}` or an error tuple.
  end