Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API endpoints misunderstand non-stringified numerical inputs #135

Open
corviday opened this issue May 5, 2020 · 0 comments
Open

API endpoints misunderstand non-stringified numerical inputs #135

corviday opened this issue May 5, 2020 · 0 comments

Comments

@corviday
Copy link
Contributor

corviday commented May 5, 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&timescale=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 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:

if time:
  # do something involving the time value
else:
  # 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:

  1. a URL that doesn't mention the parameter at all
  2. a URL that mentions the parameter but doesn't supply a value
  3. a URL that mentions the parameter and supplies a value
  4. a direct call that doesn't provide a value
  5. 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.

@corviday corviday changed the title API endpoints misunderstand directly passed 0 parameter values API endpoints misunderstand non-stringified numerical inputs May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant