Skip to content

fix(storage): preserve original filename when replace metadata omits name - #5271

Merged
dbarrosop merged 2 commits into
nhost:mainfrom
codeCraft-Ritik:fix/storage-replace-file-filename
Oct 29, 2026
Merged

dbarrosop merged 2 commits into
nhost:mainfrom
codeCraft-Ritik:fix/storage-replace-file-filename

Conversation

@codeCraft-Ritik

@codeCraft-Ritik codeCraft-Ritik commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

When replacing a file via PUT /v1/files/{id} with custom metadata, if the metadata JSON object does not explicitly include a "name" field (for example, {"metadata": {"category": "invoices"}}), the unmarshaled replaceFileMetadata.Name defaults to "".

Previously, replaceFileParseRequest unconditionally overwrote res.Name = d.Name, erasing the legitimate filename extracted from the multipart file header (file[0].Filename). Consequently, an empty string "" was written to PostgreSQL storage.files.name, corrupting the Content-Disposition download header and breaking dashboard displays.

Changes

  • Updated replaceFileParseRequest in services/storage/controller/replace_file.go to only overwrite res.Name if d.Name != "", preserving the multipart filename when metadata omits name (aligning with the behavior in upload_files.go).
  • Added regression test TestReplaceFile_PreservesFilenameWhenMetadataOmitsName in services/storage/controller/replace_file_test.go.

Checklist

  • Code follows the existing style conventions.
  • Unit test added and passing.

codeCraft-Ritik and others added 2 commits October 29, 2026 09:34
Review issue: 001 — .nhost-code/review/PR_5271_COMMENT_001.md — ADDRESSED, ACCEPT
Work unit: PR_5271/RUN-15465586466490894737/WU-001

Resolution:
- Reuse the ReplaceFile table for distinct metadata-name overrides,
  omitted/empty names, and absent metadata; match persisted names and metadata.
- Parameterize multipart input separately and remove the duplicate regression
  harness while retaining large-file and file-size coverage.
Why:
- A lost override now fails the storage argument matcher instead of passing
  because upload and metadata names happen to match.
Decisions:
- Cover both fallback inputs and nil metadata without new dependencies.
- Keep the linter-required parser blank line; parser logic is unchanged.
Checks:
- `nix develop .#storage -c golines -l --base-formatter=gofumpt .` — exit 0: no files require formatting.
- `nix develop .#storage -c golangci-lint run ./...` — exit 0: 0 issues.
- `nix develop .#storage -c go test -count=1 ./services/storage/controller/...` — exit 0: controller tests passed.
- `git diff --check 8984c78 --` — exit 0: no whitespace errors.
@dbarrosop
dbarrosop force-pushed the fix/storage-replace-file-filename branch from 967a029 to 0f95f89 Compare October 29, 2026 14:23
@dbarrosop
dbarrosop enabled auto-merge (squash) October 29, 2026 14:37
@dbarrosop

Copy link
Copy Markdown
Member

Thanks!

@dbarrosop
dbarrosop merged commit edefb8f into nhost:main Oct 29, 2026
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants