|
20 | 20 | DataDiffDbtRunResultsVersionError, |
21 | 21 | DataDiffDbtSelectNoMatchingModelsError, |
22 | 22 | DataDiffDbtSelectUnexpectedError, |
23 | | - DataDiffDbtSelectVersionTooLowError, |
24 | 23 | DataDiffDbtSnowflakeSetConnectionError, |
| 24 | + DataDiffSimpleSelectNotFound, |
25 | 25 | ) |
26 | 26 |
|
27 | 27 | from .utils import getLogger, get_from_dict_with_raise |
@@ -167,9 +167,11 @@ def get_models(self, dbt_selection: Optional[str] = None): |
167 | 167 | "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`" |
168 | 168 | ) |
169 | 169 | else: |
170 | | - raise DataDiffDbtSelectVersionTooLowError( |
171 | | - 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." |
| 170 | + # Naively get node named <dbt_selection> |
| 171 | + logger.warning( |
| 172 | + f"Full `--select` support requires dbt >= 1.5. Naively searching for a single model with name: '{dbt_selection}'." |
172 | 173 | ) |
| 174 | + return self.get_simple_model_selection(dbt_selection) |
173 | 175 | else: |
174 | 176 | return self.get_run_results_models() |
175 | 177 |
|
@@ -209,6 +211,25 @@ def get_dbt_selection_models(self, dbt_selection: str) -> List[str]: |
209 | 211 | logger.debug(str(results)) |
210 | 212 | raise DataDiffDbtSelectUnexpectedError("Encountered an unexpected error while finding `--select` models") |
211 | 213 |
|
| 214 | + def get_simple_model_selection(self, dbt_selection: str): |
| 215 | + model_nodes = dict(filter(lambda item: item[0].startswith("model."), self.dev_manifest_obj.nodes.items())) |
| 216 | + |
| 217 | + model_unique_key_list = [k for k, v in model_nodes.items() if v.name == dbt_selection] |
| 218 | + |
| 219 | + # name *should* always be unique, but just in case: |
| 220 | + if len(model_unique_key_list) > 1: |
| 221 | + logger.warning( |
| 222 | + f"Found more than one model with name '{dbt_selection}' {model_unique_key_list}, using the first one." |
| 223 | + ) |
| 224 | + elif len(model_unique_key_list) < 1: |
| 225 | + raise DataDiffSimpleSelectNotFound( |
| 226 | + f"Did not find a model node with name '{dbt_selection}' in the manifest." |
| 227 | + ) |
| 228 | + |
| 229 | + model = model_nodes.get(model_unique_key_list[0]) |
| 230 | + |
| 231 | + return [model] |
| 232 | + |
212 | 233 | def get_run_results_models(self): |
213 | 234 | with open(self.project_dir / RUN_RESULTS_PATH) as run_results: |
214 | 235 | logger.info(f"Parsing file {RUN_RESULTS_PATH}") |
|
0 commit comments