davidhuser / dhis2.py

Generic and lightweight Python wrapper for the DHIS2 API using requests
MIT License
15 stars 12 forks source link

import_response_ok is fooled by new (?) return format from the api #38

Open Gutorm opened 9 months ago

Gutorm commented 9 months ago

I am seeing this on DHIS2 2.40.0: import_response_ok assumes that the number of imports can be found through response['importCount'] Unfortunately, this has apparently been changed to response['response']['importCount']. (There two responses, the parameter-name of import_response_ok and the element returned by the api ....)

davidhuser commented 9 months ago

hi @Gutorm , many thanks for reporting it.

The import_response_ok function has been a way (or a small crutch...) to handle the inconsistencies of the DHIS2 API when it returned a 200 OK in cases when actually data values were ignored. Whether it is still a way to handle this I cannot tell, as I've not worked with recent DHIS2 versions (2.40+) or the wrapper for a while now. Ideally you would fully rely on the API response's status code instead, and report it as a bug with the DHIS2 team if it returns a 200 for a data import with ignored values?

What I always found useful was to look at the official Import/Export app in DHIS2 and open the Developer console > Network tab. Based on that you can write your own logic to make sure the import works in that particular version (e.g. through the api.version_int attribute).

At the moment I cannot find the time to update this library, but I would be happy to merge a Pull Request 😊