Skip to content

Commit a6b3cdd

Browse files
authored
Merge pull request #294 from transform-data/qmalcolm--fix-dbt-imports
Fix dbt imports
2 parents 53c9fa9 + 88f81a4 commit a6b3cdd

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

.github/workflows/ci-metricflow-unit-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
run: pip install poetry==1.1.15 && poetry config virtualenvs.create false
3333

3434
- name: Install Metricflow
35-
run: poetry install -E dbt-snowflake
35+
run: poetry install
3636

3737
- name: Run MetricFlow Unit tests suites
3838
run: pytest metricflow/test

.github/workflows/ci-schema-consistency.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
run: pip install poetry==1.1.15 && poetry config virtualenvs.create false
3737

3838
- name: Install Metricflow
39-
run: poetry install -E dbt-snowflake
39+
run: poetry install
4040

4141
- name: Generate JSON Schema
4242
run: python3 metricflow/model/parsing/explicit_schema.py

metricflow/engine/metricflow_engine.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from metricflow.dataset.convert_data_source import DataSourceToDataSetConverter
2020
from metricflow.engine.models import Dimension, Materialization, Metric
2121
from metricflow.engine.time_source import ServerTimeSource
22-
from metricflow.engine.utils import build_user_configured_model_from_config, build_user_configured_model_from_dbt_config
22+
from metricflow.engine.utils import build_user_configured_model_from_config
2323
from metricflow.execution.execution_plan import ExecutionPlan, SqlQuery
2424
from metricflow.execution.execution_plan_to_text import execution_plan_to_text
2525
from metricflow.execution.executor import SequentialPlanExecutor
@@ -276,6 +276,13 @@ def from_config(handler: YamlFileHandler) -> MetricFlowEngine:
276276
# Ideally we should put this getting of of CONFIG_DBT_REPO in a helper
277277
dbt_repo = handler.get_value(CONFIG_DBT_REPO) or ""
278278
if dbt_repo.lower() in ["yes", "y", "true", "t", "1"]:
279+
# This import results in eventually importing dbt, and dbt is an
280+
# optional dep meaning it isn't guaranteed to be installed. If the
281+
# import is at the top ofthe file MetricFlow will blow up if dbt
282+
# isn't installed. Thus by importing it here, we only run into the
283+
# exception if this conditional is hit without dbt installed
284+
from metricflow.engine.utils import build_user_configured_model_from_dbt_config
285+
279286
semantic_model = SemanticModel(build_user_configured_model_from_dbt_config(handler))
280287
else:
281288
semantic_model = SemanticModel(build_user_configured_model_from_config(handler))

metricflow/engine/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from metricflow.configuration.yaml_handler import YamlFileHandler
88
from metricflow.errors.errors import ModelCreationException
99
from metricflow.model.objects.user_configured_model import UserConfiguredModel
10-
from metricflow.model.parsing.dbt_dir_to_model import parse_dbt_project_to_model
1110
from metricflow.model.parsing.dir_to_model import ModelBuildResult, parse_directory_of_yaml_files_to_model
1211
from metricflow.sql_clients.common_client import not_empty
1312

@@ -52,6 +51,13 @@ def model_build_result_from_dbt_config(
5251
"""
5352
dbt_models_path = path_to_models(handler=handler)
5453
try:
54+
# This import results in eventually importing dbt, and dbt is an
55+
# optional dep meaning it isn't guaranteed to be installed. If the
56+
# import is at the top ofthe file MetricFlow will blow up if dbt
57+
# isn't installed. Thus by importing it here, we only run into the
58+
# exception if this method is called without dbt installed.
59+
from metricflow.model.parsing.dbt_dir_to_model import parse_dbt_project_to_model
60+
5561
return parse_dbt_project_to_model(dbt_models_path)
5662
except Exception as e:
5763
raise ModelCreationException from e

0 commit comments

Comments
 (0)