fix(client): return empty bundles on 404 instead of crashing - #16
Merged
Conversation
get_bundles() subscripted the None that fetch_resource returns on any non-200 response, so an item deleted since the cache was built (404) raised "'NoneType' object is not subscriptable" during a bitstream export - a scary CRITICAL line for what is really just "this item is gone". Record the failing response as _last_err in fetch_resource so callers can tell a gone resource (404) from a transient 5xx, then in get_bundles treat a 404 as a clean empty result. Any other failure still falls through and surfaces to the caller, so it keeps its retry and failure counting. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
A bitstream export walks every item in the cached
dspace.all.jsonand asks DSpace for each item's bundles. An item deleted from the repository since the cache was built answers404;fetch_resourcethen returnsNone, andget_bundlessubscripted thatNone:— a scary
CRITICALline for what is really just "this item is gone".Fix
fetch_resourcenow records the failing response onself._last_errbefore dropping the body, so callers can distinguish a gone resource (404) from a transient5xx.get_bundlestreats a404as a clean empty result (a deleted item simply has no bundles) and returns[].5xxkeeps its retry and is counted as a failure rather than silently recorded as an item with no files.9 lines, one file (
dspace_rest_client/client.py)._last_erris already initialised toNonein__init__, so thegetattr(...)guard is safe.Tests
Covered by
tests/test_get_bundles_missing_item.pyin the consumer repo (DSpace-ISstag-integration):404→get_bundlesreturns[](no crash)503→ still surfaces (caller retries / counts the failure)Both pass.
🤖 Generated with Claude Code