Skip to content

fix(file-naming): sync Frappe File record after physical file move#6

Open
Oval17 wants to merge 1 commit into
theapprenticeproject:mainfrom
Oval17:fix/file-duplication-on-upload
Open

fix(file-naming): sync Frappe File record after physical file move#6
Oval17 wants to merge 1 commit into
theapprenticeproject:mainfrom
Oval17:fix/file-duplication-on-upload

Conversation

@Oval17
Copy link
Copy Markdown

@Oval17 Oval17 commented May 3, 2026

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: File duplication upon upload to /files/original/

1 participant