From ee1941d0b796577787f0225cc3c1bc1351df8996 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Mon, 26 Feb 2024 07:57:15 +0100 Subject: [PATCH] Protect against the case where Airflow is checked out in AIRFLOW_HOME When airflow is checked out in the same directory as AIRFLOW_HOME, cleanup might remove everythig including .git folder. And this might happen because people might check out airflow in their HOME directory - and default AIRFLOW_HOME is ${HOME}/airflow. THis PR will detect if Airflow is checked out AIRFLOW_HOME and will error out in this case. --- dev/breeze/src/airflow_breeze/utils/path_utils.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dev/breeze/src/airflow_breeze/utils/path_utils.py b/dev/breeze/src/airflow_breeze/utils/path_utils.py index 380b1a4d5272f..bafe7be64ec87 100644 --- a/dev/breeze/src/airflow_breeze/utils/path_utils.py +++ b/dev/breeze/src/airflow_breeze/utils/path_utils.py @@ -263,7 +263,17 @@ def find_airflow_sources_root_to_operate_on() -> Path: # only print warning and sleep if not producing complete results reinstall_if_different_sources(airflow_sources) reinstall_if_setup_changed() - os.chdir(str(airflow_sources)) + os.chdir(airflow_sources.as_posix()) + airflow_home_dir = Path(os.environ.get("AIRFLOW_HOME", (Path.home() / "airflow").resolve().as_posix())) + if airflow_sources.resolve() == airflow_home_dir.resolve(): + get_console().print( + f"\n[error]Your Airflow sources are checked out in {airflow_home_dir} which " + f"is your also your AIRFLOW_HOME where airflow writes logs and database. \n" + f"This is a bad idea because Airflow might override and cleanup your checked out " + f"sources and .git repository.[/]\n" + ) + get_console().print("\nPlease check out your Airflow code elsewhere.\n") + sys.exit(1) return airflow_sources