Skip to content

Handle RecordInvalid in concurrent asset upload scenario - #1023

Merged
mwtrew merged 3 commits into
mainfrom
bug/duplicate-filename-unhandled
Sep 17, 2026
Merged

mwtrew merged 3 commits into
mainfrom
bug/duplicate-filename-unhandled

Conversation

@mwtrew

@mwtrew mwtrew commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

This arose when the first asset row is committed before validation on the second takes place.

Status

What's changed?

  • Handles RecordInvalid where it was caused by a duplicate asset upload.

This arises when the first asset is committed before validation
on the second takes place.
Copilot AI lite review requested due to automatic review settings September 17, 2026 12:04
@cla-bot cla-bot Bot added the cla-signed label Sep 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The reviewed changes address duplicate upload races with appropriate test coverage.

Pull request overview

Handles concurrent duplicate Scratch asset uploads by rescuing filename uniqueness validation failures.

Changes:

  • Reuses existing assets after duplicate upload races.
  • Preserves unrelated validation errors.
  • Adds coverage for concurrent uploads and error propagation.
File summaries
File Summary
spec/features/scratch/creating_and_showing_a_scratch_asset_spec.rb Adds concurrency and validation error coverage.
app/controllers/api/scratch/assets_controller.rb Handles duplicate filename RecordInvalid errors.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Sep 17, 2026

Copy link
Copy Markdown

Test coverage

93.58% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/35226919216

@mwtrew mwtrew changed the title Handle RecordInvalid in concurrent upload scenario Handle RecordInvalid in concurrent asset upload scenario Sep 17, 2026
@jamiebenstead
jamiebenstead requested a balanced review from Copilot September 17, 2026 12:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Attachment creation remains vulnerable to a race after the duplicate record is recovered.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread app/controllers/api/scratch/assets_controller.rb
This is done with a row-level lock on the asset row around the
S3 upload.
@mwtrew
mwtrew temporarily deployed to editor-api-p-bug-duplic-5pjdoq September 17, 2026 13:25 Inactive
@zetter-rpf

zetter-rpf commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Do you have any thoughts as to why this is happening - for example, is this caused by a project having the same asset twice? Or the same user saving a project multiple times in quick succession? Or something else?

Just trying to understand in case this points to odd behaviour in the editor uploading the same asset multiple times.

@mwtrew

mwtrew commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

@zetter-rpf I didn't look into why that might be happening from the client side - thought it was worth fixing API-side regardless, but might be worth looking into.

@mwtrew
mwtrew merged commit 9d55e54 into main Sep 17, 2026
8 checks passed
@mwtrew
mwtrew deleted the bug/duplicate-filename-unhandled branch September 17, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants