From 6f349d7e7ff60c27d1d0748c651556ac6fe2fc19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 1 May 2024 20:03:17 +0200 Subject: [PATCH] Do not test file exists when opening it The file_open tools may be used to create a file so it may not yet exist. Also io.open will raise the proper exception if the file can not be open. Closes #13230 --- trytond/trytond/tools/misc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trytond/trytond/tools/misc.py b/trytond/trytond/tools/misc.py index 0899b5f2ab..a66f56c33c 100644 --- a/trytond/trytond/tools/misc.py +++ b/trytond/trytond/tools/misc.py @@ -46,7 +46,7 @@ def import_module(name): def file_open(name, mode="r", subdir='modules', encoding=None): "Open a file from the root directory, using subdir folder" - path = find_path(name, subdir) + path = find_path(name, subdir, _test=None) return io.open(path, mode, encoding=encoding) @@ -84,7 +84,7 @@ def find_path(name, subdir='modules', _test=os.path.isfile): else: path = secure_join(root_path, name) - if _test(path): + if not _test or _test(path): return path else: raise FileNotFoundError("No such file or directory: %r" % name)