Skip to content

Raise a clear error on a Dataverse 2xx response with a bad body - #37

Merged
timlichtenberg merged 1 commit into
mainfrom
tl/dataverse-mirror-json-body-guard
Aug 31, 2026
Merged

timlichtenberg merged 1 commit into
mainfrom
tl/dataverse-mirror-json-body-guard

Conversation

@timlichtenberg

Copy link
Copy Markdown
Member

What this does

Raises a clear, diagnosable error when a Dataverse native-API call returns a 2xx status with a body that is not usable JSON, instead of the current behaviour of misreporting it as a network failure.

Why

A live test against the published Proteus_Fr collection on Dataverse.nl uploaded a file and got back a 2xx status with a body that failed to parse as JSON. The client raised an error with no status code and no response text, and the automatic rollback failed the same way, leaving an orphan draft dataset in the live collection that I had to delete by hand.

Changes

  • _request() now treats an empty 2xx body as success, since that is routine for a DELETE call.
  • Any other 2xx body that fails to parse as JSON, or that parses to something other than a JSON object, raises DataverseError with the HTTP status code and response text. This covers every endpoint (create, upload, publish, delete), not just dataset creation.
  • A non-dict JSON body such as null no longer crashes create_dataset with a bare AttributeError.
  • add_file, publish, and delete_draft no longer silently treat a bad 2xx body as success with no rollback.
  • Added tests for the empty-body and non-JSON-body cases across all four endpoints.

Testing

Full suite: 355 passed, 1 skipped (pytest). The skip is unrelated (no datasets in the shared manifest yet).

A live test against Proteus_Fr on Dataverse.nl uploaded a file and got back a 2xx status with a body that failed to parse as JSON. The client treated this the same as a network failure, so the error carried no status code and no response text, and the automatic rollback failed the same way and left an orphan draft in the live collection.

_request now treats an empty 2xx body as success (routine for a DELETE), and raises DataverseError with the status code and response text for any other body that fails to parse as JSON or parses to something other than a JSON object. This applies to every endpoint (create, upload, publish, delete), not just dataset creation, so a non-dict body like null can no longer crash create_dataset with a bare AttributeError, and a bad body on upload or publish can no longer pass silently as success with no rollback.

Add tests for the empty-body and non-JSON-body cases across all four endpoints.
@timlichtenberg
timlichtenberg merged commit fd32ecb into main Aug 31, 2026
7 checks passed
@timlichtenberg
timlichtenberg deleted the tl/dataverse-mirror-json-body-guard branch August 31, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant