diff --git a/providers/standard/src/airflow/providers/standard/operators/python.py b/providers/standard/src/airflow/providers/standard/operators/python.py index 3ab7b774c105f..53c95886ae176 100644 --- a/providers/standard/src/airflow/providers/standard/operators/python.py +++ b/providers/standard/src/airflow/providers/standard/operators/python.py @@ -889,9 +889,9 @@ def execute_callable(self): with TemporaryDirectory(prefix="venv") as tmp_dir: tmp_path = Path(tmp_dir) - tmp_dir, temp_venv_dir = tmp_path.relative_to(tmp_path.anchor).parts custom_pycache_prefix = Path(sys.pycache_prefix or "") - venv_python_cache_dir = Path.cwd() / custom_pycache_prefix / tmp_dir / temp_venv_dir + r_path = tmp_path.relative_to(tmp_path.anchor) + venv_python_cache_dir = Path.cwd() / custom_pycache_prefix / r_path self._prepare_venv(tmp_path) python_path = tmp_path / "bin" / "python" result = self._execute_python_callable_in_subprocess(python_path) diff --git a/providers/standard/tests/unit/standard/operators/test_python.py b/providers/standard/tests/unit/standard/operators/test_python.py index 3369a712da03f..4c38f9a21ad64 100644 --- a/providers/standard/tests/unit/standard/operators/test_python.py +++ b/providers/standard/tests/unit/standard/operators/test_python.py @@ -63,7 +63,11 @@ get_current_context, ) from airflow.providers.standard.utils.python_virtualenv import execute_in_subprocess, prepare_virtualenv -from airflow.utils import timezone + +try: + from airflow.sdk import timezone +except ImportError: + from airflow.utils import timezone # type: ignore[attr-defined,no-redef] from airflow.utils.session import create_session from airflow.utils.state import DagRunState, State, TaskInstanceState from airflow.utils.trigger_rule import TriggerRule @@ -1672,7 +1676,7 @@ def test_execute_callable_pycache_cleanup( ): custom_pycache_prefix = "custom/__pycache__" tempdir_name = "tmp" - venv_dir_temp_name = "venvrandom" + venv_dir_temp_name = "dummy12345/venvrandom" venv_path_tmp = f"/{tempdir_name}/{venv_dir_temp_name}" expected_cleanup_path = Path.cwd() / custom_pycache_prefix / tempdir_name / venv_dir_temp_name