pyDataverse icon indicating copy to clipboard operation
pyDataverse copied to clipboard

Fix `jsonData` not passed correctly

Open JR-1991 opened this issue 1 year ago • 7 comments

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 jsonData key is present sent through data kwarg
  • If not, JSON payload is sent through json
  • Extended tests to verify metadata is updated correctly

JR-1991 avatar Jul 19 '24 15:07 JR-1991

I can confirm that this change makes the previously failing test in datalad-dataverse pass again. Thank you!

mih avatar Jul 19 '24 15:07 mih

Nice work, @JR-1991!

pdurbin avatar Jul 19 '24 19:07 pdurbin

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 avatar Jul 24 '24 23:07 shoeffner

@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.

JR-1991 avatar Jul 26 '24 06:07 JR-1991

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?

JR-1991 avatar Jul 30 '24 08:07 JR-1991

@shoeffner are you interested in "triage" access? I just sent you an invite. You should see it at https://github.com/gdcc 😄

pdurbin avatar Jul 30 '24 14:07 pdurbin

@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.

JR-1991 avatar Aug 21 '24 10:08 JR-1991

Sorry for not responding earlier, but it looks good and I am happy it got merged!

shoeffner avatar Aug 22 '24 20:08 shoeffner