fix(file-naming): sync Frappe File record after physical file move#6
Open
Oval17 wants to merge 1 commit into
Open
fix(file-naming): sync Frappe File record after physical file move#6Oval17 wants to merge 1 commit into
Oval17 wants to merge 1 commit into
Conversation
Root cause of issue theapprenticeproject#4 (file duplication in /files/original/): file_retitling() used shutil.move() to relocate the uploaded video from /files/<filename> to /files/original/<filename>_<name>, but never updated the corresponding Frappe File doctype record. That record retained the original file_url pointing to the now-missing path. On subsequent saves of the VideoInfo document, Frappe's file management detects the broken attachment (file_url resolves to a non-existent file) and may re-upload the video, creating a duplicate entry under /files/original/. Fix: after shutil.move(), look up the File doctype record by the old file_url and update it to the new location with frappe.db.set_value(). This keeps Frappe's internal file registry in sync with the physical filesystem, preventing the orphaned record from triggering re-uploads. Fixes theapprenticeproject#4
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.
RCA and Fix for Issue #4
file_retitling() used shutil.move() to relocate the uploaded video from /files/ to /files/original/_, but never updated the corresponding Frappe File doctype record. That record retained the original file_url pointing to the now-missing path.
On subsequent saves of the VideoInfo document, Frappe's file management detects the broken attachment (file_url resolves to a non-existent file) and may re-upload the video, creating a duplicate entry under /files/original/.
Fix: after shutil.move(), look up the File doctype record by the old file_url and update it to the new location with frappe.db.set_value(). This keeps Frappe's internal file registry in sync with the physical filesystem, preventing the orphaned record from triggering re-uploads.
Fixes #4
Its Ready for Review.
Thanks