Skip to content

Commit e5c320a

Browse files
committed
fix: Conditional import for different dbt exceptions
1 parent 80c9bec commit e5c320a

File tree

1 file changed

+6
-2
lines changed
  • airflow_dbt_python/hooks

1 file changed

+6
-2
lines changed

airflow_dbt_python/hooks/dbt.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from dbt.contracts.graph.manifest import Manifest
2424
from dbt.contracts.results import RunResult
2525
from dbt.events.functions import setup_event_logger
26-
from dbt.exceptions import InternalException
2726
from dbt.graph import Graph
2827
from dbt.main import adapter_management, track_run
2928
from dbt.task.base import BaseTask, move_to_nearest_project_dir
@@ -186,6 +185,11 @@ def patch_manifest_task(self, task: ManifestTask):
186185
Raises:
187186
TypeError: If the dbt task is not a subclass of ManifestTask.
188187
"""
188+
try:
189+
from dbt.exceptions import InternalException as DbtException
190+
except ImportError:
191+
from dbt.exceptions import DbtRuntimeError as DbtException
192+
189193
if isinstance(task, ManifestTask) is False:
190194
raise TypeError(
191195
f"Patching requires an instance of ManifestTask, not {type(task)}"
@@ -220,7 +224,7 @@ def _runtime_initialize():
220224
elif uid in task.manifest.sources:
221225
task._flattened_nodes.append(task.manifest.sources[uid])
222226
else:
223-
raise InternalException(
227+
raise DbtException(
224228
f"Node selection returned {uid}, expected a node or a "
225229
f"source"
226230
)

0 commit comments

Comments
 (0)