From b21665ed6e207dbd27789107c7aee7a740a600fa Mon Sep 17 00:00:00 2001
From: allegroai <>
Date: Tue, 27 Aug 2024 22:52:01 +0300
Subject: [PATCH] Fix do not cache venv cache if venv/python skip env var was
 set

---
 clearml_agent/commands/worker.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clearml_agent/commands/worker.py b/clearml_agent/commands/worker.py
index dc80f18..35f7f36 100644
--- a/clearml_agent/commands/worker.py
+++ b/clearml_agent/commands/worker.py
@@ -3360,8 +3360,12 @@ class Worker(ServiceCommandSection):
         # disable caching with poetry because we cannot make it install into a specific folder
         # Todo: add support for poetry caching
         if not self.poetry.enabled:
-            # add to cache
-            if add_venv_folder_cache and not self._standalone_mode:
+            # disable caching if we skipped the venv creation or the entire python setup
+            if add_venv_folder_cache and not self._standalone_mode and (
+                not ENV_AGENT_SKIP_PIP_VENV_INSTALL.get() and
+                not ENV_AGENT_SKIP_PYTHON_ENV_INSTALL.get()
+            ):
+                # add to cache
                 self.package_api.add_cached_venv(
                     requirements=[freeze, previous_reqs],
                     docker_cmd=execution_info.docker_cmd if execution_info else None,