Skip to content

Resolve CSV file references with spaces against nested attachments#1208

Open
SixtyGrit wants to merge 1 commit into
samvera:mainfrom
SixtyGrit:recursive-space-normalization
Open

Resolve CSV file references with spaces against nested attachments#1208
SixtyGrit wants to merge 1 commit into
samvera:mainfrom
SixtyGrit:recursive-space-normalization

Conversation

@SixtyGrit

Copy link
Copy Markdown

Summary

CsvParser#file_paths transliterates every file reference's spaces to underscores before checking existence (f.strip.tr(' ', '_')), while #remove_spaces_from_filenames only renames the top level of files/ — and the unzip_spec added with the guided importer (#1098) pins that one-level behavior deliberately, on the rationale that renaming nested entries would break CSV references.

Those two halves contradict each other for nested attachments: a CSV referencing files/subdir/photo name.jpg can never resolve — the lookup demands the underscored variant, the disk keeps the spaces, and the import aborts with RuntimeError: File ... does not exist.

This PR makes file_paths try the reference as written first, then fall back to the underscored variant (which still matches top-level files renamed by remove_spaces_from_filenames). No on-disk renaming behavior changes, so the #1098 spec's intent is preserved.

Real-world reproduction

Hit on a Hyku 7.1.x tenant importing a per-work-folder zip (files/<work-slug>/<photos>, the layout the CSV parser's parents/children conventions encourage) where four photos had spaces in their names:

RuntimeError - File tmp/imports/.../files/files/design-square-one/Square_1_Design.png does not exist

The file existed at .../files/files/design-square-one/Square 1 Design.png. Nothing in the importer UI or validation surfaces the mismatch; the run simply dies on the first spaced reference. Operators have no reason to expect underscores: the CSV they wrote matches the files they zipped.

Notes

A related observation from the same session, possibly worth a follow-up issue: the guided importer's upload validation passed this package, and the failure only surfaced later in ImporterJob — the validator and file_paths evidently resolve attachment paths differently. Happy to file separately with details.

Changes

  • file_paths: candidate list [as-written, underscored], first existing wins; error message names the as-written reference.
  • Specs: nested-spaces resolution (as-written) + top-level fallback (underscored) + error case.

🤖 Generated with Claude Code

CsvParser#file_paths transliterated every file reference's spaces to
underscores before checking existence, while
remove_spaces_from_filenames only renames the top level of files/
(nested entries are deliberately left as-is, per the unzip_spec added
with the guided importer). A CSV referencing a nested attachment whose
name contains spaces (files/subdir/photo name.jpg) could therefore
never resolve: the lookup demanded underscores, the disk kept spaces.

Try the reference as written first, then fall back to the underscored
variant for top-level files that remove_spaces_from_filenames renamed.
@laritakr

Copy link
Copy Markdown
Contributor

@SixtyGrit If this is something you need for Hyku, it also needs to be cherrypicked onto the 9-stable branch. Hyku isn't set up to use Bulkrax main yet (that includes Rob's changes that Pals brought up re: the export permissions)

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.

2 participants