Raise a clear error on a Dataverse 2xx response with a bad body - #37
Merged
Merged
Conversation
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.
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.DataverseErrorwith the HTTP status code and response text. This covers every endpoint (create, upload, publish, delete), not just dataset creation.nullno longer crashescreate_datasetwith a bareAttributeError.add_file,publish, anddelete_draftno longer silently treat a bad 2xx body as success with no rollback.Testing
Full suite: 355 passed, 1 skipped (
pytest). The skip is unrelated (no datasets in the shared manifest yet).