From 38caf3bb227fef01383aab2d1c6f1832c35eb392 Mon Sep 17 00:00:00 2001 From: tundebabzy Date: Thu, 27 Jan 2022 08:59:43 +0100 Subject: [PATCH] fix(File): Handle file_path is None (#15552) * fix: S3 automatic backup fails when the backup folder is empty * Removed conditional that returns early when `file_path` argument is invalid i.e `None` or empty string. This means though that the function will throw an exception if it receives such invalid input so devs should check their inputs before calling the function Co-authored-by: Mohammad Hasnain Mohsin Rajan Co-authored-by: Mohammad Hasnain Mohsin Rajan --- frappe/integrations/offsite_backup_utils.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/frappe/integrations/offsite_backup_utils.py b/frappe/integrations/offsite_backup_utils.py index 416d656d90..4242676d94 100644 --- a/frappe/integrations/offsite_backup_utils.py +++ b/frappe/integrations/offsite_backup_utils.py @@ -65,10 +65,7 @@ def get_latest_backup_file(with_files=False): return database, config -def get_file_size(file_path, unit): - if not unit: - unit = "MB" - +def get_file_size(file_path, unit='MB'): file_size = os.path.getsize(file_path) memory_size_unit_mapper = {"KB": 1, "MB": 2, "GB": 3, "TB": 4} @@ -99,7 +96,7 @@ def get_chunk_site(file_size): def validate_file_size(): frappe.flags.create_new_backup = True latest_file, site_config = get_latest_backup_file() - file_size = get_file_size(latest_file, unit="GB") + file_size = get_file_size(latest_file, unit="GB") if latest_file else 0 if file_size > 1: frappe.flags.create_new_backup = False