You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this case, the API automatically receives the parameters as strings, since a URL is a string. The value of the time parameter for the multistats() function run by the above URL will be "0"
However, the API functions are sometimes called directly by other python programs processing data. In this case, the time parameter would most naturally be specified as an int 0 instead of a string "0". This produces unpredictable results because several of the API endpoints check to see whether or not a parameter has been supplied with something like this:
iftime:
# do something involving the time valueelse:
# do something without the time value
If the API is called from a URL with the value stats?time=0, the code above will directly determine that there is a value supplied for time and do something with that value. However, if it is called directly by another python program as stats(time=0) the time parameter will be falsy and the without-time-value action will happen instead.
Ways a parameter might be specified or not to the API:
a URL that doesn't mention the parameter at all
a URL that mentions the parameter but doesn't supply a value
a URL that mentions the parameter and supplies a value
a direct call that doesn't provide a value
a direct call that does provide a value
I believe right now the backend handles the first four correctly, but not the fifth in the case of numeric parameters equal to 0.
The text was updated successfully, but these errors were encountered:
corviday
changed the title
API endpoints misunderstand directly passed 0 parameter values
API endpoints misunderstand non-stringified numerical inputs
May 6, 2020
The backend is usually called with a URL, such as https://services.pacificclimate.org/pcex/api/multistats?ensemble_name=ce_files&model=PCIC12&variable=cdd&emission=historical,rcp85&time=0×cale=seasonal
In this case, the API automatically receives the parameters as strings, since a URL is a string. The value of the
time
parameter for themultistats()
function run by the above URL will be"0"
However, the API functions are sometimes called directly by other python programs processing data. In this case, the
time
parameter would most naturally be specified as an int0
instead of a string"0"
. This produces unpredictable results because several of the API endpoints check to see whether or not a parameter has been supplied with something like this:If the API is called from a URL with the value
stats?time=0
, the code above will directly determine that there is a value supplied fortime
and do something with that value. However, if it is called directly by another python program asstats(time=0)
thetime
parameter will be falsy and the without-time-value action will happen instead.Ways a parameter might be specified or not to the API:
I believe right now the backend handles the first four correctly, but not the fifth in the case of numeric parameters equal to 0.
The text was updated successfully, but these errors were encountered: