From 9460312194f3c40243ffd4262e6032d678304607 Mon Sep 17 00:00:00 2001 From: Joppe Vos <44348300+joppevos@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:00:50 +0200 Subject: [PATCH] Fix using GoogleCloudServiceAccountDictProfileMapping together with LoadMethod.DBT_LS (#587) Fix running cosmos DAGs using the profile mapping `GoogleCloudServiceAccountDictProfileMapping` and `LoadMethod.DBT_LS` render configuration. Makes the required field `keyfile_json` empty so that dbt can parse it if the `project.yaml` file is being mocked. Closes #586 --- .../bigquery/service_account_keyfile_dict.py | 5 +---- .../test_bq_service_account_keyfile_dict.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cosmos/profiles/bigquery/service_account_keyfile_dict.py b/cosmos/profiles/bigquery/service_account_keyfile_dict.py index 1c0d1391f..e84587faf 100644 --- a/cosmos/profiles/bigquery/service_account_keyfile_dict.py +++ b/cosmos/profiles/bigquery/service_account_keyfile_dict.py @@ -56,10 +56,7 @@ def mock_profile(self) -> dict[str, Any | None]: "Generates mock profile. Defaults `threads` to 1." parent_mock_profile = super().mock_profile - return { - **parent_mock_profile, - "threads": 1, - } + return {**parent_mock_profile, "threads": 1, "keyfile_json": None} def transform_keyfile_json(self, keyfile_json: str | dict[str, str]) -> dict[str, str]: """ diff --git a/tests/profiles/bigquery/test_bq_service_account_keyfile_dict.py b/tests/profiles/bigquery/test_bq_service_account_keyfile_dict.py index 8a260ec2f..0647e6800 100644 --- a/tests/profiles/bigquery/test_bq_service_account_keyfile_dict.py +++ b/tests/profiles/bigquery/test_bq_service_account_keyfile_dict.py @@ -72,6 +72,22 @@ def test_profile(mock_bigquery_conn_with_dict: Connection): assert profile_mapping.profile == expected +def test_mock_profile(mock_bigquery_conn_with_dict: Connection): + """ + Tests profile mock for keyfile_json is None. Giving keyfile_json a value will crash dbt ls. + """ + profile_mapping = GoogleCloudServiceAccountDictProfileMapping(mock_bigquery_conn_with_dict, {}) + expected = { + "type": "bigquery", + "method": "service-account-json", + "project": "mock_value", + "dataset": "mock_value", + "threads": 1, + "keyfile_json": None, + } + assert profile_mapping.mock_profile == expected + + def test_profile_env_vars(mock_bigquery_conn_with_dict: Connection): """ Tests that the environment variables get set correctly.