drive icon indicating copy to clipboard operation
drive copied to clipboard

fix(files): Handle root level files in remove_or_restore

Open bvisible opened this issue 2 months ago • 0 comments

Summary

Fixes TypeError when deleting or restoring files at root level (files with no parent folder).

Problem

Files at root level have parent_entity = NULL. When trying to delete/restore them via remove_or_restore, the code attempts to update the parent folder's file_size:

folder_size = frappe.db.get_value("Drive File", doc.parent_entity, "file_size")
frappe.db.set_value(..., folder_size + doc.file_size * ...)

This fails with:

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Solution

  • Added check if doc.parent_entity: before updating parent folder size
  • Added or 0 fallback for safety in case parent exists but has NULL file_size

Testing

  • Tested on production instance with files at root level
  • Verified delete and restore operations work correctly

bvisible avatar Dec 31 '25 15:12 bvisible