Skip to content

Conversation

@JR-1991
Copy link
Member

@JR-1991 JR-1991 commented Mar 19, 2025

As noted in #216, the process for modifying the metadata of a dataset has malfunctioned due to multiple values being sent to json. This PR resolves the problem and includes tests to verify functionality.

@JR-1991 JR-1991 added type:bug Something isn't working prio:high labels Mar 19, 2025
@JR-1991 JR-1991 added this to the 0.3.5 milestone Mar 19, 2025
@JR-1991 JR-1991 self-assigned this Mar 19, 2025
@JR-1991 JR-1991 moved this to Ready for Review in PyDataverse Working Group Mar 19, 2025
test.py Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this file should have been omitted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, thanks a lot! Removed it 🥲

Copy link
Member

@pdurbin pdurbin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about it and it makes sense. Approving.

@jp-tosca jp-tosca requested a review from Copilot June 18, 2025 14:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR corrects the edit_dataset_metadata endpoint by sending metadata as request body parameters instead of JSON to avoid multiple values being passed to json, and adds tests to verify both replace and add behaviors.

  • Updated put_request to accept a data payload and removed automatic JSON encoding for PUT.
  • Adjusted edit_dataset_metadata to call put_request with data=metadata.
  • Added two integration tests covering replace and add scenarios for dataset metadata edits.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/api/test_edit.py New tests for replace and add modes of edit_dataset_metadata.
pyDataverse/api.py Changed put_request signature, removed json= usage, and updated metadata edit to use request body.
Comments suppressed due to low confidence (1)

tests/api/test_edit.py:84

  • [nitpick] Update the docstring for test_edit_dataset_metadata_add to correctly describe that this test adds metadata rather than replacing existing metadata.
        2. Edits the dataset metadata and replaces the existing metadata.

API_TOKEN = os.getenv("API_TOKEN")

# Create dataset
metadata = json.load(open("tests/data/file_upload_ds_minimum.json"))
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Use a context manager when opening files (e.g., with open(...) as f:) to ensure the file is properly closed.

Suggested change
metadata = json.load(open("tests/data/file_upload_ds_minimum.json"))
with open("tests/data/file_upload_ds_minimum.json") as f:
metadata = json.load(f)

Copilot uses AI. Check for mistakes.
request_params = self._check_json_data_form(data)

if self.client is None:
return self._sync_request(
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new files parameter is accepted by put_request but not forwarded to the underlying request; include files=files in both _sync_request and _async_request calls to support file uploads via PUT.

Copilot uses AI. Check for mistakes.
@JR-1991 JR-1991 merged commit 50a5e26 into main Aug 15, 2025
10 checks passed
@github-project-automation github-project-automation bot moved this from Ready for Review to Done in PyDataverse Working Group Aug 15, 2025
@JR-1991 JR-1991 deleted the fix-edit-metadata-endpoint branch August 15, 2025 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prio:high type:bug Something isn't working

Projects

Development

Successfully merging this pull request may close these issues.

Error when using edit_dataset_metadata: multiple values for keyword argument 'json'

4 participants