Skip to content

Commit

Permalink
Fix using GoogleCloudServiceAccountDictProfileMapping together with L…
Browse files Browse the repository at this point in the history
…oadMethod.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
  • Loading branch information
joppevos authored Oct 10, 2023
1 parent 3786703 commit 9460312
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 1 addition & 4 deletions cosmos/profiles/bigquery/service_account_keyfile_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand Down
16 changes: 16 additions & 0 deletions tests/profiles/bigquery/test_bq_service_account_keyfile_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9460312

Please sign in to comment.