12
12
from dbt .config .renderer import ProfileRenderer
13
13
14
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 ,
15
+ DataDiffDbtBigQueryOauthOnlyError ,
16
+ DataDiffDbtConnectionNotImplementedError ,
17
+ DataDiffDbtCoreNoRunnerError ,
18
+ DataDiffDbtNoSuccessfulModelsInRunError ,
19
+ DataDiffDbtProfileNotFoundError ,
20
+ DataDiffDbtProjectVarsNotFoundError ,
21
+ DataDiffDbtRedshiftPasswordOnlyError ,
22
+ DataDiffDbtRunResultsVersionError ,
23
+ DataDiffDbtSelectNoMatchingModelsError ,
24
+ DataDiffDbtSelectUnexpectedError ,
25
+ DataDiffDbtSelectVersionTooLowError ,
26
+ DataDiffDbtSnowflakeSetConnectionError ,
27
27
)
28
28
29
29
from .utils import getLogger , get_from_dict_with_raise
@@ -108,7 +108,7 @@ def __init__(self, profiles_dir_override: str, project_dir_override: str) -> Non
108
108
109
109
def get_datadiff_variables (self ) -> dict :
110
110
doc_url = "https://docs.datafold.com/development_testing/open_source#configure-your-dbt-project"
111
- exception = DbtProjectVarsNotFoundError (
111
+ exception = DataDiffDbtProjectVarsNotFoundError (
112
112
f"vars: data_diff: section not found in dbt_project.yml.\n \n To solve this, please configure your dbt project: \n { doc_url } \n "
113
113
)
114
114
vars_dict = get_from_dict_with_raise (self .project_dict , "vars" , exception )
@@ -137,11 +137,11 @@ def get_models(self, dbt_selection: Optional[str] = None):
137
137
return self .get_dbt_selection_models (dbt_selection )
138
138
# edge case if running data-diff from a separate env than dbt (likely local development)
139
139
else :
140
- raise DbtCoreNoRunnerError (
140
+ raise DataDiffDbtCoreNoRunnerError (
141
141
"data-diff is using a dbt-core version < 1.5, update the environment's dbt-core version via pip install 'dbt-core>=1.5' in order to use `--select`"
142
142
)
143
143
else :
144
- raise DbtSelectVersionTooLowError (
144
+ raise DataDiffDbtSelectVersionTooLowError (
145
145
f"The `--select` feature requires dbt >= 1.5, but your project's manifest.json is from dbt v{ dbt_version } . Please follow these steps to use the `--select` feature: \n 1. Update your dbt-core version via pip install 'dbt-core>=1.5'. Details: https://docs.getdbt.com/docs/core/pip-install#change-dbt-core-versions \n 2. Execute any `dbt` command (`run`, `compile`, `build`) to create a new manifest.json."
146
146
)
147
147
else :
@@ -178,10 +178,10 @@ def get_dbt_selection_models(self, dbt_selection: str) -> List[str]:
178
178
return models
179
179
180
180
if not results .result :
181
- raise DbtSelectNoMatchingModelsError (f"No dbt models found for `--select { dbt_selection } `" )
181
+ raise DataDiffDbtSelectNoMatchingModelsError (f"No dbt models found for `--select { dbt_selection } `" )
182
182
183
183
logger .debug (str (results ))
184
- raise DbtSelectUnexpectedError ("Encountered an unexpected error while finding `--select` models" )
184
+ raise DataDiffDbtSelectUnexpectedError ("Encountered an unexpected error while finding `--select` models" )
185
185
186
186
def get_run_results_models (self ):
187
187
with open (self .project_dir / RUN_RESULTS_PATH ) as run_results :
@@ -195,7 +195,7 @@ def get_run_results_models(self):
195
195
self .profiles_dir = legacy_profiles_dir ()
196
196
197
197
if dbt_version < parse_version (LOWER_DBT_V ):
198
- raise DbtRunResultsVersionError (
198
+ raise DataDiffDbtRunResultsVersionError (
199
199
f"Found dbt: v{ dbt_version } Expected the dbt project's version to be >= { LOWER_DBT_V } "
200
200
)
201
201
if dbt_version >= parse_version (UPPER_DBT_V ):
@@ -206,7 +206,7 @@ def get_run_results_models(self):
206
206
success_models = [x .unique_id for x in run_results_obj .results if x .status .name == "success" ]
207
207
models = [self .manifest_obj .nodes .get (x ) for x in success_models ]
208
208
if not models :
209
- raise DbtNoSuccessfulModelsInRunError ("Expected > 0 successful models runs from the last dbt command." )
209
+ raise DataDiffDbtNoSuccessfulModelsInRunError ("Expected > 0 successful models runs from the last dbt command." )
210
210
211
211
print (f"Running with data-diff={ __version__ } \n " )
212
212
return models
@@ -235,31 +235,31 @@ def get_connection_creds(self) -> Tuple[Dict[str, str], str]:
235
235
profile = get_from_dict_with_raise (
236
236
profiles ,
237
237
dbt_profile_var ,
238
- DbtProfileNotFoundError (f"No profile '{ dbt_profile_var } ' found in '{ profiles_path } '." ),
238
+ DataDiffDbtProfileNotFoundError (f"No profile '{ dbt_profile_var } ' found in '{ profiles_path } '." ),
239
239
)
240
240
# values can contain env_vars
241
241
rendered_profile = ProfileRenderer ().render_data (profile )
242
242
profile_target = get_from_dict_with_raise (
243
243
rendered_profile ,
244
244
"target" ,
245
- DbtProfileNotFoundError (f"No target found in profile '{ dbt_profile_var } ' in '{ profiles_path } '." ),
245
+ DataDiffDbtProfileNotFoundError (f"No target found in profile '{ dbt_profile_var } ' in '{ profiles_path } '." ),
246
246
)
247
247
outputs = get_from_dict_with_raise (
248
248
rendered_profile ,
249
249
"outputs" ,
250
- DbtProfileNotFoundError (f"No outputs found in profile '{ dbt_profile_var } ' in '{ profiles_path } '." ),
250
+ DataDiffDbtProfileNotFoundError (f"No outputs found in profile '{ dbt_profile_var } ' in '{ profiles_path } '." ),
251
251
)
252
252
credentials = get_from_dict_with_raise (
253
253
outputs ,
254
254
profile_target ,
255
- DbtProfileNotFoundError (
255
+ DataDiffDbtProfileNotFoundError (
256
256
f"No credentials found for target '{ profile_target } ' in profile '{ dbt_profile_var } ' in '{ profiles_path } '."
257
257
),
258
258
)
259
259
conn_type = get_from_dict_with_raise (
260
260
credentials ,
261
261
"type" ,
262
- DbtProfileNotFoundError (
262
+ DataDiffDbtProfileNotFoundError (
263
263
f"No type found for target '{ profile_target } ' in profile '{ dbt_profile_var } ' in '{ profiles_path } '."
264
264
),
265
265
)
@@ -287,7 +287,7 @@ def set_connection(self):
287
287
288
288
if credentials .get ("private_key_path" ) is not None :
289
289
if credentials .get ("password" ) is not None :
290
- raise DbtSnowflakeSetConnectionError ("Cannot use password and key at the same time" )
290
+ raise DataDiffDbtSnowflakeSetConnectionError ("Cannot use password and key at the same time" )
291
291
conn_info ["key" ] = credentials .get ("private_key_path" )
292
292
conn_info ["private_key_passphrase" ] = credentials .get ("private_key_passphrase" )
293
293
elif credentials .get ("authenticator" ) is not None :
@@ -296,13 +296,13 @@ def set_connection(self):
296
296
elif credentials .get ("password" ) is not None :
297
297
conn_info ["password" ] = credentials .get ("password" )
298
298
else :
299
- raise DbtSnowflakeSetConnectionError ("Snowflake: unsupported auth method" )
299
+ raise DataDiffDbtSnowflakeSetConnectionError ("Snowflake: unsupported auth method" )
300
300
elif conn_type == "bigquery" :
301
301
method = credentials .get ("method" )
302
302
# there are many connection types https://docs.getdbt.com/reference/warehouse-setups/bigquery-setup#oauth-via-gcloud
303
303
# this assumes that the user is auth'd via `gcloud auth application-default login`
304
304
if method is None or method != "oauth" :
305
- raise DbtBigQueryOauthOnlyError ("Oauth is the current method supported for Big Query." )
305
+ raise DataDiffDbtBigQueryOauthOnlyError ("Oauth is the current method supported for Big Query." )
306
306
conn_info = {
307
307
"driver" : conn_type ,
308
308
"project" : credentials .get ("project" ),
@@ -318,7 +318,7 @@ def set_connection(self):
318
318
if (credentials .get ("pass" ) is None and credentials .get ("password" ) is None ) or credentials .get (
319
319
"method"
320
320
) == "iam" :
321
- raise DbtRedshiftPasswordOnlyError ("Only password authentication is currently supported for Redshift." )
321
+ raise DataDiffDbtRedshiftPasswordOnlyError ("Only password authentication is currently supported for Redshift." )
322
322
conn_info = {
323
323
"driver" : conn_type ,
324
324
"host" : credentials .get ("host" ),
@@ -349,7 +349,7 @@ def set_connection(self):
349
349
}
350
350
self .threads = credentials .get ("threads" )
351
351
else :
352
- raise DbtConnectionNotImplementedError (f"Provider { conn_type } is not yet supported for dbt diffs" )
352
+ raise DataDiffDbtConnectionNotImplementedError (f"Provider { conn_type } is not yet supported for dbt diffs" )
353
353
354
354
self .connection = conn_info
355
355
0 commit comments