Skip to content

Stop 500ing on a v3 manifest that has no canvases - #414

Open
ShanaLMoore wants to merge 1 commit into
mainfrom
fix-v3-manifest-sanitize
Open

ShanaLMoore wants to merge 1 commit into
mainfrom
fix-v3-manifest-sanitize

Conversation

@ShanaLMoore

Copy link
Copy Markdown
Contributor

Story

Refs notch8/hykuup_knapsack#748

Expected Behavior Before Changes

sanitize_v3 did hash['items'].each with no guard, so a manifest with no items key raised NoMethodError (undefined method 'each' for nil) and the work's viewer showed "Unable to load manifest". sanitize_v2 has always guarded the equivalent loop.

Two ways to reach it: a work whose presenter yields no displayable file sets, and a v2-shaped hash sanitized as v3, which is what Hyrax's CachingIiifManifestBuilder produced until samvera/hyrax#7590 (it defaulted to the v2 factory while IiifPrint.config.default_iiif_manifest_version stayed 3). That combination took out roughly half the works on two production tenants.

Expected Behavior After Changes

A manifest with no canvases is returned as-is instead of 500ing.

Notes

  • The label scrub on the line above used Hash#key, which takes a value, not a key, so it returned nil and the scrub never ran. Fixed to a lookup, which means canvas labels get scrubbed now too. Both call sites share one method that tolerates a missing label.
  • Hyrax's fix is the real one for the caching mismatch; this is the guard so a factory/version mismatch degrades instead of 500ing.

Testing

spec/services/iiif_print/manifest_builder_service_decorator_spec.rb covers the canvas-less manifest, the label unescape, and a manifest with no label. Not run locally (needs the full engine cart stack); CI runs the suite.

🤖 Assisted-by: Opus 5

sanitize_v3 called `hash['items'].each` with no guard, so a manifest
without an 'items' key raised NoMethodError and the work's viewer showed
"Unable to load manifest". Two ways to get there: a work whose presenter
yields no displayable file sets, and a v2-shaped hash sanitized as v3,
which is what Hyrax's CachingIiifManifestBuilder produced until samvera/hyrax#7590.
sanitize_v2 has always guarded its equivalent loop.

The label scrub next to it used `Hash#key`, which takes a value, so it
returned nil and the scrub never ran. Fixing it to a lookup means canvas
labels now get scrubbed too, so both call sites go through one method
that tolerates a missing label.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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