From 65f6727af3c8197195b68510e2591687468212ea Mon Sep 17 00:00:00 2001 From: subramanya-dev Date: Fri, 12 Jun 2026 20:04:20 +0530 Subject: [PATCH 1/2] fix(dagster-dbt): improve error messages for missing dbt adapter and invalid target_path - Wrap `dbt.adapters` import in `compat.py` with an actionable ModuleNotFoundError that suggests installing the correct adapter package - Add the same ModuleNotFoundError guard in `_initialize_dbt_core_adapter` for the `dbt.adapters.factory` import - Split the bare `except:` in `cli()` adapter init into a specific ModuleNotFoundError branch with an installation hint, and an Exception fallback for other errors - Add an explicit isinstance check for `target_path` in `cli()` to surface a clear ValueError instead of an AttributeError when a str is passed --- .../dagster-dbt/dagster_dbt/compat.py | 18 +++++++--- .../dagster-dbt/dagster_dbt/core/resource.py | 35 +++++++++++++++++-- 2 files changed, 45 insertions(+), 8 deletions(-) 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..6d65f3963dd46 100644 --- a/python_modules/libraries/dagster-dbt/dagster_dbt/core/resource.py +++ b/python_modules/libraries/dagster-dbt/dagster_dbt/core/resource.py @@ -361,7 +361,15 @@ def _get_unique_target_path( return current_target_path.joinpath(path) def _initialize_dbt_core_adapter(self, args: Sequence[str]) -> BaseAdapter: - from dbt.adapters.factory import get_adapter, register_adapter, reset_adapters + try: + from dbt.adapters.factory import get_adapter, register_adapter, reset_adapters + 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.config import RuntimeConfig from dbt.config.runtime import load_profile, load_project from dbt.config.utils import parse_cli_vars @@ -646,7 +654,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 +731,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) or "dbt-" 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, From fafd58d7cad0638661d8c50c2cb3dce21d855db9 Mon Sep 17 00:00:00 2001 From: subramanya-dev Date: Fri, 12 Jun 2026 20:25:26 +0530 Subject: [PATCH 2/2] fix(dagster-dbt): surface actionable errors for missing dbt adapter and invalid target_path - In `compat.py`, wrap the `dbt.adapters.base.impl` module-level import with a `ModuleNotFoundError` handler that tells users which adapter package to install (e.g. dbt-postgres, dbt-bigquery, dbt-snowflake) - In `cli()`, replace the bare `except:` with a split handler: a `ModuleNotFoundError` branch that emits a targeted installation hint when `dbt.adapters` is missing, and an `Exception` fallback that preserves the original generic warning for unrelated failures - Add an explicit `isinstance(target_path, Path)` guard in `cli()` that raises a clear `ValueError` instead of a cryptic `AttributeError: 'str' object has no attribute 'is_absolute'` --- .../dagster-dbt/dagster_dbt/core/resource.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) 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 6d65f3963dd46..f180b1c73822f 100644 --- a/python_modules/libraries/dagster-dbt/dagster_dbt/core/resource.py +++ b/python_modules/libraries/dagster-dbt/dagster_dbt/core/resource.py @@ -361,15 +361,7 @@ def _get_unique_target_path( return current_target_path.joinpath(path) def _initialize_dbt_core_adapter(self, args: Sequence[str]) -> BaseAdapter: - try: - from dbt.adapters.factory import get_adapter, register_adapter, reset_adapters - 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.adapters.factory import get_adapter, register_adapter, reset_adapters from dbt.config import RuntimeConfig from dbt.config.runtime import load_profile, load_project from dbt.config.utils import parse_cli_vars @@ -732,7 +724,7 @@ def my_dbt_op(dbt: DbtCliResource): try: adapter = self._initialize_dbt_core_adapter(args) except ModuleNotFoundError as e: - if "dbt.adapters" in str(e) or "dbt-" in str(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:"