From fd14ac2cfdfbb9990d20004076e9a1c1b64669db Mon Sep 17 00:00:00 2001 From: Tatiana Al-Chueyr Date: Wed, 6 Aug 2025 17:19:25 +0100 Subject: [PATCH 1/2] Fix the local tests dbt ls cache (outside of the CI) --- tests/dbt/test_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dbt/test_graph.py b/tests/dbt/test_graph.py index 38f993cfb..b17cf704d 100644 --- a/tests/dbt/test_graph.py +++ b/tests/dbt/test_graph.py @@ -1908,7 +1908,7 @@ def test_save_dbt_ls_cache(mock_variable_set, mock_datetime, tmp_dbt_project_dir assert hash_args == "d41d8cd98f00b204e9800998ecf8427e" if sys.platform == "darwin": # We faced inconsistent hashing versions depending on the version of MacOS/Linux - the following line aims to address these. - assert hash_dir in ("c2c47529eaec412281bdb243a479b734", "71bbf303ad4e06a7b1e2be20e0b73c0d") + assert hash_dir in ("e16e6aef5f03f4e12d744b9412d90272", "71bbf303ad4e06a7b1e2be20e0b73c0d") else: assert hash_dir == "71bbf303ad4e06a7b1e2be20e0b73c0d" From 737ea5560a075c8c008e52f81f782b7dce799c32 Mon Sep 17 00:00:00 2001 From: Tatiana Al-Chueyr Date: Wed, 6 Aug 2025 17:32:04 +0100 Subject: [PATCH 2/2] Fix cache behaviour when DAG name contains . Cosmos stores the result of dbt ls as a Variable based on the DAG name, but if the name has a . in it, that Variable name will be invalid when working with certain secret managers, including Google cloud's. This is an example of error that is raised: ``` Invalid secret ID myhost-cosmos_cache__dag.moredag.yetmoredag Only ASCII alphabets (a-Z), numbers (0-9), dashes (-), and underscores (_) are allowed in the secret ID. ``` In this PR, we replace those names to use underscores instead of dot. Closes: #1875 --- cosmos/cache.py | 2 +- tests/test_cache.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cosmos/cache.py b/cosmos/cache.py index 98cca4054..ed17725bd 100644 --- a/cosmos/cache.py +++ b/cosmos/cache.py @@ -123,7 +123,7 @@ def _create_cache_identifier(dag: DAG, task_group: TaskGroup | None) -> str: task_group_id = metadata.get("task_group_id") if dag_id: - cache_identifiers_list.append(dag_id) + cache_identifiers_list.append(dag_id.replace(".", "___")) if task_group_id: cache_identifiers_list.append(task_group_id.replace(".", "__")) diff --git a/tests/test_cache.py b/tests/test_cache.py index 8734ab2ec..cb0d778b8 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -50,6 +50,8 @@ START_DATE = datetime(2024, 4, 16) example_dag = DAG("dag", start_date=START_DATE) +example_dag_with_dots = DAG("dag.with.dots", start_date=START_DATE) + SAMPLE_PARTIAL_PARSE_FILEPATH = Path(__file__).parent / "sample/partial_parse.msgpack" @@ -57,6 +59,7 @@ "dag, task_group, result_identifier", [ (example_dag, None, "dag"), + (example_dag_with_dots, None, "dag___with___dots"), (None, TaskGroup(dag=example_dag, group_id="inner_tg"), "dag__inner_tg"), ( None,