Fix model files lost after validation error on create (#2582)#2590
Open
stuzart wants to merge 13 commits into
Open
Fix model files lost after validation error on create (#2582)#2590stuzart wants to merge 13 commits into
stuzart wants to merge 13 commits into
Conversation
…and avoid skipping callbacks when saving blobs #2582
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2582 — uploaded model files were silently lost when a validation error occurred during creation and the user resubmitted the form.
Root cause:
ContentBlobrecords built on an unsavedModelhave no database ID. Theexisting_file.hbstemplate uses{{id}}to populateretained_content_blob_ids[]hidden fields, so withid = nilthe fields submitted as empty strings and the files were discarded on resubmit.ContentBlobrecords as orphans (noasset_id) so they get real database IDs the form can referenceasset_id/asset_type/asset_versionto point to the newly created modelvalidateUploadFormFieldsinvalidation.jsto also checkretained_content_blob_ids[]inputs, preventing a spurious "Please specify at least a file/image" alert on resubmitOrphaned blobs from abandoned sessions are cleaned up by the existing
RegularMaintenanceJob#remove_dangling_content_blobsafter 8 hours.Changes
lib/seek/assets_standard_controller_actions.rb—preserve_content_blobs_for_rerenderandattach_retained_orphaned_content_blobslib/seek/upload_handling/data_upload.rb—load_orphaned_content_blobsusingadd_to_target; usesafe_retained_content_blob_idsthroughoutlib/seek/upload_handling/parameter_handling.rb—retained_content_blob_idsandsafe_retained_content_blob_ids(session-based allowlist)app/assets/javascripts/upload.js— hide "No file chosen" text when files are already listedapp/assets/javascripts/validation.js— check retained blob IDs in client-side validation; scope retained selector to parent whenparentIdis setapp/assets/stylesheets/styles.scss— CSS to hide the file input label text when files are pendingtest/functional/models_controller_test.rb— end-to-end tests covering failed → successful resubmit and tampered ID rejectionCloses #2582