fix: raise when presigned URL response is missing or malformed#5073
Conversation
|
/request-review @aicam |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5073 +/- ##
============================================
- Coverage 43.15% 43.02% -0.13%
+ Complexity 2213 2201 -12
============================================
Files 1045 1045
Lines 40353 40147 -206
Branches 4267 4229 -38
============================================
- Hits 17413 17272 -141
+ Misses 21865 21815 -50
+ Partials 1075 1060 -15
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
aicam
left a comment
There was a problem hiding this comment.
LGTM. Replaces a silent None return (which previously caused requests.get(None) downstream in read_file() with a confusing TypeError) with explicit RuntimeErrors for the three failure modes: invalid JSON, missing key, and non-string/empty value. Error messages quote response.text for diagnosability.
Verified locally (Python 3.12)
$ pytest src/test/python/pytexera/storage/test_dataset_file_document.py -v
============================== 21 passed in 0.50s ==============================
All 21 tests pass, including the 3 new negative-path tests (test_raises_when_response_body_lacks_presigned_url_key, test_raises_when_response_body_is_not_valid_json, test_raises_when_presigned_url_is_empty_string, test_raises_when_presigned_url_is_not_a_string).
Tight, focused fix.
What changes were proposed in this PR?
DatasetFileDocument.get_presigned_urlpreviously returnedresponse.json().get("presignedUrl")on a 200 response, so a body that omitted the key (or wasn't valid JSON) silently returnedNone. This PR parses the JSON inside a try/except block and validates thatpresignedUrlis a non-empty string; otherwise, it raisesRuntimeErrorwith the response body.Any related issues, documentation, or discussions?
Closes: #4725
How was this PR tested?
Manually reproduced the missing-key case (mocked 200 + empty JSON) and confirmed the new
RuntimeErroris raised at the presign step instead of a downstreamrequests.get(None)failure.Was this PR authored or co-authored using generative AI tooling?
Co-authored with Claude Opus 4.7 in compliance with ASF