Closed cbenz closed 7 years ago
EDIT: import from duplicate #74: — @MattiSG
As a user of the API, When I ask to compute a variable (e.g. PPA) for a period it can't be calculated (e.g. a year), I get a clear error message to help me understand why my request is rejected
When triggering a simulation with the wrong period:
{"scenarios":[{"axes":[[{"count":10,"index":0,"name":"heures_remunerees_volume","min":0,"max":151.67,"period":null}]],"period":"2015","test_case":{"familles":[{"id":0,"parents":["ind0"]}],"foyers_fiscaux":[{"id":0,"declarants":["ind0"]}],"individus":[{"id":"ind0","contrat_de_travail":1,"date_naissance":"1980-01-01"}],"menages":[{"id":0,"personne_de_reference":"ind0"}]}}],"variables":["allegement_fillon"],"trace":true}
The API raises an error 500:
[Mon Jul 25 16:25:13.052562 2016] [wsgi:error] [pid 21266:tid 140148156176128] 16:25:13,052 ERROR [openfisca_web_api.application] Requested period 2015 differs from 2015-01 returned by variable allegement_fillon [Mon Jul 25 16:25:13.052901 2016] [wsgi:error] [pid 21266:tid 140148156176128] Traceback (most recent call last): [Mon Jul 25 16:25:13.052953 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/home/openfisca/openfisca-web-api/openfisca_web_api/application.py", line 56, in respond_json_exception [Mon Jul 25 16:25:13.052999 2016] [wsgi:error] [pid 21266:tid 140148156176128] return app(environ, start_response) [Mon Jul 25 16:25:13.053037 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/home/openfisca/openfisca-web-api/openfisca_web_api/application.py", line 76, in set_x_api_version_header [Mon Jul 25 16:25:13.053080 2016] [wsgi:error] [pid 21266:tid 140148156176128] res = req.get_response(app) [Mon Jul 25 16:25:13.053107 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/usr/local/lib/python2.7/dist-packages/webob/request.py", line 1317, in send [Mon Jul 25 16:25:13.053130 2016] [wsgi:error] [pid 21266:tid 140148156176128] application, catch_exc_info=False) [Mon Jul 25 16:25:13.053152 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/usr/local/lib/python2.7/dist-packages/webob/request.py", line 1281, in call_application [Mon Jul 25 16:25:13.053174 2016] [wsgi:error] [pid 21266:tid 140148156176128] app_iter = application(self.environ, start_response) [Mon Jul 25 16:25:13.053196 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/home/openfisca/openfisca-web-api/openfisca_web_api/application.py", line 42, in set_environment [Mon Jul 25 16:25:13.053218 2016] [wsgi:error] [pid 21266:tid 140148156176128] return app(req.environ, start_response) [Mon Jul 25 16:25:13.053239 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/home/openfisca/openfisca-web-api/openfisca_web_api/urls.py", line 115, in router [Mon Jul 25 16:25:13.053266 2016] [wsgi:error] [pid 21266:tid 140148156176128] return app(req.environ, start_response) [Mon Jul 25 16:25:13.053290 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 130, in __call__ [Mon Jul 25 16:25:13.053311 2016] [wsgi:error] [pid 21266:tid 140148156176128] resp = self.call_func(req, *args, **self.kwargs) [Mon Jul 25 16:25:13.053338 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 195, in call_func [Mon Jul 25 16:25:13.053361 2016] [wsgi:error] [pid 21266:tid 140148156176128] return self.func(req, *args, **kwargs) [Mon Jul 25 16:25:13.053382 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/home/openfisca/openfisca-web-api/openfisca_web_api/controllers/calculate.py", line 351, in api1_calculate [Mon Jul 25 16:25:13.053404 2016] [wsgi:error] [pid 21266:tid 140148156176128] base_simulations = calculate_simulations(scenarios, data['variables'], trace = trace_simulations) [Mon Jul 25 16:25:13.053426 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/home/openfisca/openfisca-web-api/openfisca_web_api/controllers/calculate.py", line 84, in calculate_simulations [Mon Jul 25 16:25:13.053449 2016] [wsgi:error] [pid 21266:tid 140148156176128] simulation.calculate_output(variable_name) [Mon Jul 25 16:25:13.053555 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/home/openfisca/openfisca-core/openfisca_core/simulations.py", line 96, in calculate_output [Mon Jul 25 16:25:13.053581 2016] [wsgi:error] [pid 21266:tid 140148156176128] return holder.calculate_output(period) [Mon Jul 25 16:25:13.053602 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/home/openfisca/openfisca-core/openfisca_core/holders.py", line 92, in calculate_output [Mon Jul 25 16:25:13.053624 2016] [wsgi:error] [pid 21266:tid 140148156176128] return self.formula.calculate_output(period) [Mon Jul 25 16:25:13.053646 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/home/openfisca/openfisca-core/openfisca_core/formulas.py", line 54, in calculate_output [Mon Jul 25 16:25:13.053667 2016] [wsgi:error] [pid 21266:tid 140148156176128] return self.holder.compute(period).array [Mon Jul 25 16:25:13.053688 2016] [wsgi:error] [pid 21266:tid 140148156176128] File "/home/openfisca/openfisca-core/openfisca_core/holders.py", line 142, in compute [Mon Jul 25 16:25:13.053710 2016] [wsgi:error] [pid 21266:tid 140148156176128] formula_dated_holder.period, column.name) [Mon Jul 25 16:25:13.053731 2016] [wsgi:error] [pid 21266:tid 140148156176128] AssertionError: Requested period 2015 differs from 2015-01 returned by variable allegement_fillon
It should return a 400 with a JSON payload representing the error.
Fixed via https://github.com/openfisca/openfisca-web-api/pull/111.
EDIT: import from duplicate #74: — @MattiSG
As a user of the API, When I ask to compute a variable (e.g. PPA) for a period it can't be calculated (e.g. a year), I get a clear error message to help me understand why my request is rejected
When triggering a simulation with the wrong period:
The API raises an error 500:
It should return a 400 with a JSON payload representing the error.