Skip to content

Fix model files lost after validation error on create (#2582)#2590

Open
stuzart wants to merge 13 commits into
seek-1.18from
fix-model-files-after-validation-2582
Open

Fix model files lost after validation error on create (#2582)#2590
stuzart wants to merge 13 commits into
seek-1.18from
fix-model-files-after-validation-2582

Conversation

@stuzart
Copy link
Copy Markdown
Member

@stuzart stuzart commented May 20, 2026

Summary

Fixes #2582 — uploaded model files were silently lost when a validation error occurred during creation and the user resubmitted the form.

Root cause: ContentBlob records built on an unsaved Model have no database ID. The existing_file.hbs template uses {{id}} to populate retained_content_blob_ids[] hidden fields, so with id = nil the fields submitted as empty strings and the files were discarded on resubmit.

  • On validation failure, save the in-memory ContentBlob records as orphans (no asset_id) so they get real database IDs the form can reference
  • On resubmit, load those orphaned blobs back into the in-memory association so they are treated as already-attached
  • On successful save, update the orphaned blobs' asset_id/asset_type/asset_version to point to the newly created model
  • Use the session as an ownership allowlist for retained blob IDs, preventing a user from attaching blobs they did not upload by tampering with params
  • Fix client-side validateUploadFormFields in validation.js to also check retained_content_blob_ids[] inputs, preventing a spurious "Please specify at least a file/image" alert on resubmit
  • Hide the "No file chosen" label beside the file input button when files are already shown in the pending list

Orphaned blobs from abandoned sessions are cleaned up by the existing RegularMaintenanceJob#remove_dangling_content_blobs after 8 hours.

Changes

  • lib/seek/assets_standard_controller_actions.rbpreserve_content_blobs_for_rerender and attach_retained_orphaned_content_blobs
  • lib/seek/upload_handling/data_upload.rbload_orphaned_content_blobs using add_to_target; use safe_retained_content_blob_ids throughout
  • lib/seek/upload_handling/parameter_handling.rbretained_content_blob_ids and safe_retained_content_blob_ids (session-based allowlist)
  • app/assets/javascripts/upload.js — hide "No file chosen" text when files are already listed
  • app/assets/javascripts/validation.js — check retained blob IDs in client-side validation; scope retained selector to parent when parentId is set
  • app/assets/stylesheets/styles.scss — CSS to hide the file input label text when files are pending
  • test/functional/models_controller_test.rb — end-to-end tests covering failed → successful resubmit and tampered ID rejection

Closes #2582

@stuzart stuzart marked this pull request as draft May 20, 2026 14:51

This comment was marked as outdated.

This comment was marked as outdated.

@stuzart stuzart marked this pull request as ready for review May 27, 2026 15:32
@stuzart stuzart requested a review from fbacall May 27, 2026 15:32
@stuzart stuzart added this to the 1.18.0 milestone May 27, 2026
@stuzart stuzart moved this to In review in SEEK 1.18.x May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants