From ab087a81da15ebe43b1d1511117c19b50ff1b973 Mon Sep 17 00:00:00 2001 From: Yuri Chiucconi Date: Fri, 8 Nov 2024 17:50:32 +0100 Subject: [PATCH 1/7] open log file in context manager --- fractal_server/tasks/v2/utils_background.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fractal_server/tasks/v2/utils_background.py b/fractal_server/tasks/v2/utils_background.py index 596b1f03ad..3d92d3a4df 100644 --- a/fractal_server/tasks/v2/utils_background.py +++ b/fractal_server/tasks/v2/utils_background.py @@ -167,6 +167,7 @@ def _refresh_logs( Read logs from file and update them in the db. """ task_group_activity = db.get(TaskGroupActivityV2, task_group_activity_id) - task_group_activity.log = log_file_path.open("r").read() + with log_file_path.open("r") as f: + task_group_activity.log = f.read() db.add(task_group_activity) db.commit() From b322ea7727e11a22fe92da16fb92abf231a48192 Mon Sep 17 00:00:00 2001 From: Yuri Chiucconi Date: Fri, 8 Nov 2024 17:55:37 +0100 Subject: [PATCH 2/7] remove debug --- fractal_server/tasks/v2/collection_local.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/fractal_server/tasks/v2/collection_local.py b/fractal_server/tasks/v2/collection_local.py index e18fb5066a..7fd653dc10 100644 --- a/fractal_server/tasks/v2/collection_local.py +++ b/fractal_server/tasks/v2/collection_local.py @@ -159,9 +159,7 @@ def collect_package_local( "Now new wheel_path " f"is {task_group.wheel_path} - end" ) - from devtools import debug - debug(task_group) python_bin = get_python_interpreter_v2( python_version=task_group.python_version ) From b7579fc01d723d3f6087a40ae251aae922c182a9 Mon Sep 17 00:00:00 2001 From: Yuri Chiucconi Date: Tue, 12 Nov 2024 15:34:48 +0100 Subject: [PATCH 3/7] test it actually fails --- tests/v2/03_api/test_api_task_collection.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/v2/03_api/test_api_task_collection.py b/tests/v2/03_api/test_api_task_collection.py index a569a3ec24..1587bcbd23 100644 --- a/tests/v2/03_api/test_api_task_collection.py +++ b/tests/v2/03_api/test_api_task_collection.py @@ -69,6 +69,10 @@ async def test_task_collection_from_wheel( assert res.status_code == 200 task_group_activity = res.json() debug(task_group_activity) + + assert task_group_activity["log"].count("\n") > 0 + assert task_group_activity["log"].count("\\n") == 0 + assert task_group_activity["status"] == "OK" assert task_group_activity["timestamp_ended"] is not None # Check that log were written, even with CRITICAL logging level From 88ccc508196146ec1624588aa06492d8cee9265b Mon Sep 17 00:00:00 2001 From: Yuri Chiucconi Date: Tue, 12 Nov 2024 15:54:14 +0100 Subject: [PATCH 4/7] first possible solution --- fractal_server/tasks/v2/utils_background.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fractal_server/tasks/v2/utils_background.py b/fractal_server/tasks/v2/utils_background.py index 0f1df06f4e..29d386b48e 100644 --- a/fractal_server/tasks/v2/utils_background.py +++ b/fractal_server/tasks/v2/utils_background.py @@ -142,4 +142,6 @@ def check_task_files_exist(task_list: list[TaskCreateV2]) -> None: def get_current_log(logger_file_path: str) -> str: with open(logger_file_path, "r") as f: - return f.read() + current_log = f.read() + current_log = current_log.replace("\\n", "\n") + return current_log From 9f21cb80aa30ce00fd55aa384cc1612dd18fb38d Mon Sep 17 00:00:00 2001 From: Tommaso Comparin <3862206+tcompa@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:16:40 +0100 Subject: [PATCH 5/7] Restore `get_current_log` from `main` --- fractal_server/tasks/v2/utils_background.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fractal_server/tasks/v2/utils_background.py b/fractal_server/tasks/v2/utils_background.py index 29d386b48e..0f1df06f4e 100644 --- a/fractal_server/tasks/v2/utils_background.py +++ b/fractal_server/tasks/v2/utils_background.py @@ -142,6 +142,4 @@ def check_task_files_exist(task_list: list[TaskCreateV2]) -> None: def get_current_log(logger_file_path: str) -> str: with open(logger_file_path, "r") as f: - current_log = f.read() - current_log = current_log.replace("\\n", "\n") - return current_log + return f.read() From 00aebcba790c7671e89a273fff62ba6f92f28d75 Mon Sep 17 00:00:00 2001 From: Tommaso Comparin <3862206+tcompa@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:17:48 +0100 Subject: [PATCH 6/7] Do not write `{stdout=}` within a log --- fractal_server/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fractal_server/utils.py b/fractal_server/utils.py index 34a901f3e8..12109239d5 100644 --- a/fractal_server/utils.py +++ b/fractal_server/utils.py @@ -108,8 +108,10 @@ def execute_command_sync( stdout = res.stdout stderr = res.stderr logger.debug(f"{returncode=}") - logger.debug(f"{stdout=}") - logger.debug(f"{stderr=}") + logger.debug("STDOUT:") + logger.debug(stdout) + logger.debug("STDERR:") + logger.debug(stderr) if res.returncode != 0: logger.debug(f"ERROR in subprocess call to '{command}'") raise RuntimeError( From 37a329e443c023c3539194751ff8408be64223ea Mon Sep 17 00:00:00 2001 From: Yuri Chiucconi Date: Wed, 13 Nov 2024 09:02:25 +0100 Subject: [PATCH 7/7] changelog [skip ci] --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc95991536..d90df58d7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ * Refactor bash templates and add `install_from_freeze.sh` (\#2029). * SSH internals: * Add `FractalSSH.remote_exists` method (\#2008). +* Internal: + * Fix escaping of newlines within f-strings (\#2028). # 2.8.1