diff --git a/python_modules/libraries/dagster-dbt/dagster_dbt/compat.py b/python_modules/libraries/dagster-dbt/dagster_dbt/compat.py index 0e536d0bb9f95..86d4d40fa2c53 100644 --- a/python_modules/libraries/dagster-dbt/dagster_dbt/compat.py +++ b/python_modules/libraries/dagster-dbt/dagster_dbt/compat.py @@ -40,11 +40,19 @@ REFABLE_NODE_TYPES: list[str] = [] else: if DBT_PYTHON_VERSION is not None: - from dbt.adapters.base.impl import ( - BaseAdapter as BaseAdapter, - BaseColumn as BaseColumn, - BaseRelation as BaseRelation, - ) + try: + from dbt.adapters.base.impl import ( + BaseAdapter as BaseAdapter, + BaseColumn as BaseColumn, + BaseRelation as BaseRelation, + ) + except ModuleNotFoundError as e: + raise ModuleNotFoundError( + "A dbt adapter package could not be found.\n\n" + "Please install the appropriate dbt adapter for your data platform " + "(for example: dbt-postgres, dbt-bigquery, or dbt-snowflake).\n\n" + f"Original error:\n{e}" + ) from e from dbt.contracts.results import NodeStatus, TestStatus from dbt.node_types import NodeType as NodeType diff --git a/python_modules/libraries/dagster-dbt/dagster_dbt/core/resource.py b/python_modules/libraries/dagster-dbt/dagster_dbt/core/resource.py index 0e2b47463c5f7..f180b1c73822f 100644 --- a/python_modules/libraries/dagster-dbt/dagster_dbt/core/resource.py +++ b/python_modules/libraries/dagster-dbt/dagster_dbt/core/resource.py @@ -646,7 +646,13 @@ def my_dbt_op(dbt: DbtCliResource): dagster_dbt_translator = updated_params.dagster_dbt_translator selection_args = updated_params.selection_args indirect_selection = updated_params.indirect_selection - target_path = target_path or self._get_unique_target_path(context=context) + raw_target_path = target_path or self._get_unique_target_path(context=context) + if not isinstance(raw_target_path, Path): + raise ValueError( + f"The 'target_path' argument must be a pathlib.Path, not {type(raw_target_path).__name__!r}." + " Pass a Path object, for example: target_path=Path('target')." + ) + target_path = raw_target_path project_dir = Path( updated_params.dbt_project.project_dir if updated_params.dbt_project @@ -717,7 +723,22 @@ def my_dbt_op(dbt: DbtCliResource): if self._cli_version.major < 2: try: adapter = self._initialize_dbt_core_adapter(args) - except: + except ModuleNotFoundError as e: + if "dbt.adapters" in str(e): + logger.warning( + "A dbt adapter package could not be loaded. Please install the" + " appropriate dbt adapter for your data platform (for example:" + " dbt-postgres, dbt-bigquery, or dbt-snowflake). Some Dagster" + " features that require a live connection to your data platform" + " will be unavailable.\n\nOriginal error: %s", + e, + ) + else: + logger.warning( + "An error was encountered when creating a handle to the dbt adapter in Dagster.", + exc_info=True, + ) + except Exception: logger.warning( "An error was encountered when creating a handle to the dbt adapter in Dagster.", exc_info=True,