Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 42d330a

Browse files
committed
format
1 parent c8f3d9d commit 42d330a

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

data_diff/dbt_parser.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@
1111
from dbt_artifacts_parser.parser import parse_run_results, parse_manifest
1212
from dbt.config.renderer import ProfileRenderer
1313

14-
from data_diff.errors import DbtBigQueryOauthOnlyError, DbtConnectionNotImplementedError, DbtCoreNoRunnerError, DbtNoSuccessfulModelsInRunError, DbtProfileNotFoundError, DbtProjectVarsNotFoundError, DbtRedshiftPasswordOnlyError, DbtRunResultsVersionError, DbtSelectNoMatchingModelsError, DbtSelectUnexpectedError, DbtSelectVersionTooLowError, DbtSnowflakeSetConnectionError
14+
from data_diff.errors import (
15+
DbtBigQueryOauthOnlyError,
16+
DbtConnectionNotImplementedError,
17+
DbtCoreNoRunnerError,
18+
DbtNoSuccessfulModelsInRunError,
19+
DbtProfileNotFoundError,
20+
DbtProjectVarsNotFoundError,
21+
DbtRedshiftPasswordOnlyError,
22+
DbtRunResultsVersionError,
23+
DbtSelectNoMatchingModelsError,
24+
DbtSelectUnexpectedError,
25+
DbtSelectVersionTooLowError,
26+
DbtSnowflakeSetConnectionError,
27+
)
1528

1629
from .utils import getLogger, get_from_dict_with_raise
1730
from .version import __version__
@@ -95,7 +108,9 @@ def __init__(self, profiles_dir_override: str, project_dir_override: str) -> Non
95108

96109
def get_datadiff_variables(self) -> dict:
97110
doc_url = "https://docs.datafold.com/development_testing/open_source#configure-your-dbt-project"
98-
exception = DbtProjectVarsNotFoundError(f"vars: data_diff: section not found in dbt_project.yml.\n\nTo solve this, please configure your dbt project: \n{doc_url}\n")
111+
exception = DbtProjectVarsNotFoundError(
112+
f"vars: data_diff: section not found in dbt_project.yml.\n\nTo solve this, please configure your dbt project: \n{doc_url}\n"
113+
)
99114
vars_dict = get_from_dict_with_raise(self.project_dict, "vars", exception)
100115
return get_from_dict_with_raise(vars_dict, "data_diff", exception)
101116

@@ -180,7 +195,9 @@ def get_run_results_models(self):
180195
self.profiles_dir = legacy_profiles_dir()
181196

182197
if dbt_version < parse_version(LOWER_DBT_V):
183-
raise DbtRunResultsVersionError(f"Found dbt: v{dbt_version} Expected the dbt project's version to be >= {LOWER_DBT_V}")
198+
raise DbtRunResultsVersionError(
199+
f"Found dbt: v{dbt_version} Expected the dbt project's version to be >= {LOWER_DBT_V}"
200+
)
184201
if dbt_version >= parse_version(UPPER_DBT_V):
185202
logger.warning(
186203
f"{dbt_version} is a recent version of dbt and may not be fully tested with data-diff! \nPlease report any issues to https://github.com/datafold/data-diff/issues"
@@ -216,25 +233,35 @@ def get_connection_creds(self) -> Tuple[Dict[str, str], str]:
216233
dbt_profile_var = self.project_dict.get("profile")
217234

218235
profile = get_from_dict_with_raise(
219-
profiles, dbt_profile_var, DbtProfileNotFoundError(f"No profile '{dbt_profile_var}' found in '{profiles_path}'.")
236+
profiles,
237+
dbt_profile_var,
238+
DbtProfileNotFoundError(f"No profile '{dbt_profile_var}' found in '{profiles_path}'."),
220239
)
221240
# values can contain env_vars
222241
rendered_profile = ProfileRenderer().render_data(profile)
223242
profile_target = get_from_dict_with_raise(
224-
rendered_profile, "target", DbtProfileNotFoundError(f"No target found in profile '{dbt_profile_var}' in '{profiles_path}'.")
243+
rendered_profile,
244+
"target",
245+
DbtProfileNotFoundError(f"No target found in profile '{dbt_profile_var}' in '{profiles_path}'."),
225246
)
226247
outputs = get_from_dict_with_raise(
227-
rendered_profile, "outputs", DbtProfileNotFoundError(f"No outputs found in profile '{dbt_profile_var}' in '{profiles_path}'.")
248+
rendered_profile,
249+
"outputs",
250+
DbtProfileNotFoundError(f"No outputs found in profile '{dbt_profile_var}' in '{profiles_path}'."),
228251
)
229252
credentials = get_from_dict_with_raise(
230253
outputs,
231254
profile_target,
232-
DbtProfileNotFoundError(f"No credentials found for target '{profile_target}' in profile '{dbt_profile_var}' in '{profiles_path}'."),
255+
DbtProfileNotFoundError(
256+
f"No credentials found for target '{profile_target}' in profile '{dbt_profile_var}' in '{profiles_path}'."
257+
),
233258
)
234259
conn_type = get_from_dict_with_raise(
235260
credentials,
236261
"type",
237-
DbtProfileNotFoundError(f"No type found for target '{profile_target}' in profile '{dbt_profile_var}' in '{profiles_path}'."),
262+
DbtProfileNotFoundError(
263+
f"No type found for target '{profile_target}' in profile '{dbt_profile_var}' in '{profiles_path}'."
264+
),
238265
)
239266
conn_type = conn_type.lower()
240267

data_diff/errors.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,46 @@
1-
21
class DbtProjectVarsNotFoundError(Exception):
32
"Raised when an expected dbt_project.yml section is missing."
43

4+
55
class DbtProfileNotFoundError(Exception):
66
"Raised when an expected profiles.yml section is missing."
77

8+
89
class DbtNoSuccessfulModelsInRunError(Exception):
910
"Raised when there are no successful model runs in the run_results.json"
1011

12+
1113
class DbtRunResultsVersionError(Exception):
1214
"Raised when the dbt version in run_results.json is lower than the minimum version."
1315

16+
1417
class DbtSelectNoMatchingModelsError(Exception):
1518
"Raised when the `--select` flag returns no models."
1619

20+
1721
class DbtSelectUnexpectedError(Exception):
1822
"Catch all for unexpected dbt list --select results."
1923

24+
2025
class DbtSnowflakeSetConnectionError(Exception):
2126
"Raised when a dbt snowflake profile has unexpected values."
2227

28+
2329
class DbtBigQueryOauthOnlyError(Exception):
2430
"Raised when trying to use a method other than oauth with BigQuery."
2531

32+
2633
class DbtRedshiftPasswordOnlyError(Exception):
2734
"Raised when using a non-password connection method with Redshift."
2835

36+
2937
class DbtConnectionNotImplementedError(Exception):
3038
"Raised when trying to use an unsupported dbt connection method."
3139

40+
3241
class DbtCoreNoRunnerError(Exception):
3342
"Raised when the manifest version >= 1.5, but the dbt-core package is < 1.5. This is an edge case most likely to occur in development."
3443

44+
3545
class DbtSelectVersionTooLowError(Exception):
36-
"Raised when attempting to use `--select` with a dbt-core version < 1.5."
46+
"Raised when attempting to use `--select` with a dbt-core version < 1.5."

tests/test_dbt.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@
44
from data_diff.cloud.datafold_api import TCloudApiDataSource
55
from data_diff.cloud.datafold_api import TCloudApiOrgMeta
66
from data_diff.diff_tables import Algorithm
7-
from data_diff.errors import DbtBigQueryOauthOnlyError, DbtConnectionNotImplementedError, DbtCoreNoRunnerError, DbtNoSuccessfulModelsInRunError, DbtProfileNotFoundError, DbtProjectVarsNotFoundError, DbtRedshiftPasswordOnlyError, DbtRunResultsVersionError, DbtSelectVersionTooLowError, DbtSnowflakeSetConnectionError
7+
from data_diff.errors import (
8+
DbtBigQueryOauthOnlyError,
9+
DbtConnectionNotImplementedError,
10+
DbtCoreNoRunnerError,
11+
DbtNoSuccessfulModelsInRunError,
12+
DbtProfileNotFoundError,
13+
DbtProjectVarsNotFoundError,
14+
DbtRedshiftPasswordOnlyError,
15+
DbtRunResultsVersionError,
16+
DbtSelectVersionTooLowError,
17+
DbtSnowflakeSetConnectionError,
18+
)
819
from .test_cli import run_datadiff_cli
920

1021
from data_diff.dbt import (

0 commit comments

Comments
 (0)