Skip to content

fix(client): return empty bundles on 404 instead of crashing - #16

Merged
vidiecan merged 1 commit into
dtqfrom
fix/get-bundles-404-empty-not-crash
Aug 17, 2026
Merged

fix(client): return empty bundles on 404 instead of crashing#16
vidiecan merged 1 commit into
dtqfrom
fix/get-bundles-404-empty-not-crash

Conversation

@vidiecan

Copy link
Copy Markdown

Problem

A bitstream export walks every item in the cached dspace.all.json and asks DSpace for each item's bundles. An item deleted from the repository since the cache was built answers 404; fetch_resource then returns None, and get_bundles subscripted that None:

'NoneType' object is not subscriptable

— a scary CRITICAL line for what is really just "this item is gone".

Fix

  • fetch_resource now records the failing response on self._last_err before dropping the body, so callers can distinguish a gone resource (404) from a transient 5xx.
  • get_bundles treats a 404 as a clean empty result (a deleted item simply has no bundles) and returns [].
  • Any other failure still falls through and surfaces to the caller, so a transient 5xx keeps 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_err is already initialised to None in __init__, so the getattr(...) guard is safe.

Tests

Covered by tests/test_get_bundles_missing_item.py in the consumer repo (DSpace-ISstag-integration):

  • 404get_bundles returns [] (no crash)
  • 503 → still surfaces (caller retries / counts the failure)

Both pass.

🤖 Generated with Claude Code

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>
@vidiecan
vidiecan merged commit f9ca942 into dtq Aug 17, 2026
@vidiecan
vidiecan deleted the fix/get-bundles-404-empty-not-crash branch August 17, 2026 07:02
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