-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(dagster-dbt): improve error messages for missing dbt adapter and invalid target_path #33924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||||||||||||||||
|
Comment on lines
+649
to
+655
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
| 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, | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
Comment on lines
+726
to
+740
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Additionally, the condition Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||||||||||||||||||
| except Exception: | ||||||||||||||||||||||||||||
| logger.warning( | ||||||||||||||||||||||||||||
| "An error was encountered when creating a handle to the dbt adapter in Dagster.", | ||||||||||||||||||||||||||||
| exc_info=True, | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dbt.adapters.base.impllives in thedbt-adapterspackage, which is a core dependency ofdbt-core, not a specific adapter package. If this import fails withModuleNotFoundError, it meansdbt-adaptersitself is absent (e.g., a broken or partial install), not that a platform-specific adapter likedbt-postgresis missing. Installingdbt-postgreswould indirectly fix the issue (it pulls indbt-adapters), but a user who already hasdbt-postgresinstalled would be confused by being told to install it again. The message would be more accurate if it mentioneddbt-adaptersas the primary fix, with platform adapters as the second suggestion.