Skip to content

Commit 3c2ae3c

Browse files
fix: Catch missing dbt parser dependency in dbt CLI commands (feast-dev#6534)
* fix(dbt): handle missing dbt-artifacts-parser import errors in CLI Catch ImportError in `feast dbt import` and `feast dbt list` so missing dbt parser dependency returns a clean CLI error. Add regression tests to verify both commands exit with actionable install guidance. Signed-off-by: kchawlani19 <[email protected]> Co-authored-by: Cursor <[email protected]> * test(dbt): make import error CLI assertions robust Signed-off-by: kchawlani19 <[email protected]> * test(dbt): make CLI error output assertions click-version safe Signed-off-by: kchawlani19 <[email protected]> * fix(dbt): tolerate unsupported macro languages in dbt manifests Signed-off-by: kchawlani19 <[email protected]> --------- Signed-off-by: kchawlani19 <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 6019bd6 commit 3c2ae3c

4 files changed

Lines changed: 150 additions & 6 deletions

File tree

‎sdk/python/feast/cli/dbt_import.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ def import_command(
130130
try:
131131
parser = DbtManifestParser(manifest_path)
132132
parser.parse()
133-
except FileNotFoundError as e:
134-
click.echo(f"{Fore.RED}Error: {e}{Style.RESET_ALL}", err=True)
135-
raise SystemExit(1)
136-
except ValueError as e:
133+
except (FileNotFoundError, ValueError, ImportError) as e:
137134
click.echo(f"{Fore.RED}Error: {e}{Style.RESET_ALL}", err=True)
138135
raise SystemExit(1)
139136

@@ -374,7 +371,7 @@ def list_command(
374371
try:
375372
parser = DbtManifestParser(manifest_path)
376373
parser.parse()
377-
except (FileNotFoundError, ValueError) as e:
374+
except (FileNotFoundError, ValueError, ImportError) as e:
378375
click.echo(f"{Fore.RED}Error: {e}{Style.RESET_ALL}", err=True)
379376
raise SystemExit(1)
380377

‎sdk/python/feast/dbt/parser.py‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99

1010
import json
11+
from copy import deepcopy
1112
from dataclasses import dataclass, field
1213
from pathlib import Path
1314
from typing import Any, Dict, List, Optional
@@ -79,6 +80,34 @@ def __init__(self, manifest_path: str):
7980
self._raw_manifest: Optional[Dict[str, Any]] = None
8081
self._parsed_manifest: Optional[Any] = None
8182

83+
@staticmethod
84+
def _sanitize_supported_languages(manifest: Dict[str, Any]) -> Dict[str, Any]:
85+
"""
86+
Remove unsupported macro language values before typed parsing.
87+
88+
dbt may emit values like "javascript" in `macros.*.supported_languages`,
89+
while dbt-artifacts-parser currently accepts only "python" and "sql".
90+
Since Feast only needs model metadata, dropping unknown values is safe.
91+
"""
92+
manifest_copy = deepcopy(manifest)
93+
macros = manifest_copy.get("macros", {})
94+
if not isinstance(macros, dict):
95+
return manifest_copy
96+
97+
for macro in macros.values():
98+
if not isinstance(macro, dict):
99+
continue
100+
101+
supported_languages = macro.get("supported_languages")
102+
if isinstance(supported_languages, list):
103+
macro["supported_languages"] = [
104+
language
105+
for language in supported_languages
106+
if language in {"python", "sql"}
107+
]
108+
109+
return manifest_copy
110+
82111
def parse(self) -> None:
83112
"""
84113
Load and parse the manifest.json file using dbt-artifacts-parser.
@@ -108,7 +137,15 @@ def parse(self) -> None:
108137
from dbt_artifacts_parser.parser import parse_manifest
109138

110139
assert self._raw_manifest is not None
111-
self._parsed_manifest = parse_manifest(manifest=self._raw_manifest)
140+
try:
141+
self._parsed_manifest = parse_manifest(manifest=self._raw_manifest)
142+
except Exception as e:
143+
if "supported_languages" not in str(e):
144+
raise
145+
sanitized_manifest = self._sanitize_supported_languages(
146+
self._raw_manifest
147+
)
148+
self._parsed_manifest = parse_manifest(manifest=sanitized_manifest)
112149
except ImportError:
113150
raise ImportError(
114151
"dbt-artifacts-parser is required for dbt integration.\n"

‎sdk/python/tests/integration/dbt/test_dbt_integration.py‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,16 @@ def test_codegen_online_false(self, parser):
10251025
class TestDbtCli:
10261026
"""Test the `feast dbt import` and `feast dbt list` CLI commands."""
10271027

1028+
@staticmethod
1029+
def _get_cli_output(result) -> str:
1030+
"""Return combined stdout/stderr across Click versions."""
1031+
stderr = getattr(result, "stderr", "")
1032+
if not stderr:
1033+
stderr_bytes = getattr(result, "stderr_bytes", b"")
1034+
if stderr_bytes:
1035+
stderr = stderr_bytes.decode("utf-8", errors="replace")
1036+
return result.output + stderr
1037+
10281038
def test_dbt_list_command(self, manifest_path):
10291039
from click.testing import CliRunner
10301040

@@ -1061,6 +1071,27 @@ def test_dbt_list_show_columns(self, manifest_path):
10611071
assert "driver_id" in result.output
10621072
assert "conv_rate" in result.output
10631073

1074+
def test_dbt_list_import_error(self, manifest_path, monkeypatch):
1075+
from click.testing import CliRunner
1076+
1077+
from feast.cli.dbt_import import list_command
1078+
from feast.dbt.parser import DbtManifestParser
1079+
1080+
def _raise_import_error(self): # pragma: no cover - behavior tested via CLI
1081+
raise ImportError(
1082+
"dbt-artifacts-parser is required for dbt integration.\n"
1083+
"Install with: pip install 'feast[dbt]' or pip install dbt-artifacts-parser"
1084+
)
1085+
1086+
monkeypatch.setattr(DbtManifestParser, "parse", _raise_import_error)
1087+
1088+
runner = CliRunner()
1089+
result = runner.invoke(list_command, ["-m", manifest_path])
1090+
output = self._get_cli_output(result)
1091+
assert result.exit_code == 1
1092+
assert "dbt-artifacts-parser is required for dbt integration" in output
1093+
assert "feast[dbt]" in output
1094+
10641095
def test_dbt_import_dry_run(self, manifest_path):
10651096
from click.testing import CliRunner
10661097

@@ -1086,6 +1117,38 @@ def test_dbt_import_dry_run(self, manifest_path):
10861117
assert result.exit_code == 0
10871118
assert "Dry run" in result.output
10881119

1120+
def test_dbt_import_import_error(self, manifest_path, monkeypatch):
1121+
from click.testing import CliRunner
1122+
1123+
from feast.cli.dbt_import import import_command
1124+
from feast.dbt.parser import DbtManifestParser
1125+
1126+
def _raise_import_error(self): # pragma: no cover - behavior tested via CLI
1127+
raise ImportError(
1128+
"dbt-artifacts-parser is required for dbt integration.\n"
1129+
"Install with: pip install 'feast[dbt]' or pip install dbt-artifacts-parser"
1130+
)
1131+
1132+
monkeypatch.setattr(DbtManifestParser, "parse", _raise_import_error)
1133+
1134+
runner = CliRunner()
1135+
result = runner.invoke(
1136+
import_command,
1137+
[
1138+
"-m",
1139+
manifest_path,
1140+
"-e",
1141+
"driver_id",
1142+
"--dry-run",
1143+
],
1144+
obj={"CHDIR": ".", "FS_YAML_FILE": "feature_store.yaml"},
1145+
catch_exceptions=False,
1146+
)
1147+
output = self._get_cli_output(result)
1148+
assert result.exit_code == 1
1149+
assert "dbt-artifacts-parser is required for dbt integration" in output
1150+
assert "feast[dbt]" in output
1151+
10891152
def test_dbt_import_output_codegen(self, manifest_path, tmp_path):
10901153
from click.testing import CliRunner
10911154

‎sdk/python/tests/unit/dbt/test_parser.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,53 @@ def test_parse_manifest_invalid_json(self, tmp_path):
172172

173173
assert "Invalid JSON" in str(exc_info.value)
174174

175+
def test_parse_retries_with_sanitized_supported_languages(
176+
self, tmp_path, monkeypatch
177+
):
178+
"""Test parser retries after removing unsupported macro languages."""
179+
manifest = {
180+
"metadata": {
181+
"dbt_schema_version": "https://schemas.getdbt.com/dbt/manifest/v12.json",
182+
"dbt_version": "1.11.11",
183+
},
184+
"nodes": {},
185+
"macros": {
186+
"macro.dbt.materialization_function_default": {
187+
"name": "materialization_function_default",
188+
"supported_languages": ["python", "sql", "javascript"],
189+
}
190+
},
191+
}
192+
manifest_path = tmp_path / "manifest.json"
193+
manifest_path.write_text(json.dumps(manifest))
194+
195+
class _ParsedManifest:
196+
nodes = {}
197+
metadata = None
198+
199+
call_manifests = []
200+
201+
def _fake_parse_manifest(*, manifest):
202+
call_manifests.append(manifest)
203+
if len(call_manifests) == 1:
204+
raise Exception("supported_languages Input should be 'python' or 'sql'")
205+
return _ParsedManifest()
206+
207+
monkeypatch.setattr(
208+
"dbt_artifacts_parser.parser.parse_manifest", _fake_parse_manifest
209+
)
210+
211+
parser = DbtManifestParser(str(manifest_path))
212+
parser.parse()
213+
214+
assert len(call_manifests) == 2
215+
assert call_manifests[0]["macros"][
216+
"macro.dbt.materialization_function_default"
217+
]["supported_languages"] == ["python", "sql", "javascript"]
218+
assert call_manifests[1]["macros"][
219+
"macro.dbt.materialization_function_default"
220+
]["supported_languages"] == ["python", "sql"]
221+
175222
def test_get_all_models(self, sample_manifest):
176223
"""Test getting all models from manifest."""
177224
parser = DbtManifestParser(str(sample_manifest))

0 commit comments

Comments
 (0)