Fix `jsonData` not passed correctly
Overview
This PR addresses the issue reported at https://github.com/datalad/datalad-dataverse/issues/320, where metadata sent via NativeApi.replace_datafile wasn’t updating the file metadata correctly. The problem arose because the jsonData payload needs to be sent as form-data, which HTTPX’s json kwarg doesn’t handle properly.
The fix involves sending the payload via the data argument. However, since other endpoints require data to be sent through the json argument, this PR introduces a private method in api.py to determine the correct way to send the data. This method checks for the presence of the jsonData key and adjusts the argument accordingly. If the key isn’t found, the json argument is used by default.
To prevent similar issues in the future, the tests have been updated. The replace_datafile tests now ensure that the metadata is correctly updated.
TLDR
- If
jsonDatakey is present sent throughdatakwarg - If not, JSON payload is sent through
json - Extended tests to verify metadata is updated correctly
I can confirm that this change makes the previously failing test in datalad-dataverse pass again. Thank you!
Nice work, @JR-1991!
Please note @adswa's changes in datalad/datalad-dataverse#322 and my alternative fix in #207, which is a PR onto this branch, not the main branch.
@shoeffner, thanks for the notice and the PR! Once I return from vacation, I will add a test to check for empty json_str to this PR.
I've included a test case to verify whether the behavior is as expected when json_str is set to None in the case of uploading a file. Would either @shoeffner or @pdurbin be available to review the PR?
@shoeffner are you interested in "triage" access? I just sent you an invite. You should see it at https://github.com/gdcc 😄
@shoeffner I have updated this PR and specifically the tests to use pyDataverse methods instead of manual requests, as highlighted by you. The PR is now ready for review.
Sorry for not responding earlier, but it looks good and I am happy it got merged!