diff --git a/metricflow-semantics/metricflow_semantics/api/v0_1/saved_query_dependency_resolver.py b/metricflow-semantics/metricflow_semantics/api/v0_1/saved_query_dependency_resolver.py index 50893504cf..4367720272 100644 --- a/metricflow-semantics/metricflow_semantics/api/v0_1/saved_query_dependency_resolver.py +++ b/metricflow-semantics/metricflow_semantics/api/v0_1/saved_query_dependency_resolver.py @@ -2,7 +2,7 @@ import logging from dataclasses import dataclass -from typing import Tuple +from typing import Optional, Tuple from dbt_semantic_interfaces.protocols import SemanticManifest from dbt_semantic_interfaces.references import ( @@ -34,9 +34,19 @@ class SavedQueryDependencyResolver: def __init__(self, semantic_manifest: SemanticManifest) -> None: # noqa: D107 self._semantic_manifest = semantic_manifest - self._query_parser = MetricFlowQueryParser(SemanticManifestLookup(semantic_manifest)) + # TODO: There seems to be issues with an empty manifest, so doing this check for now. + self._query_parser: Optional[MetricFlowQueryParser] = None + if len(semantic_manifest.semantic_models) > 0: + self._query_parser = MetricFlowQueryParser(SemanticManifestLookup(semantic_manifest)) def _resolve_dependencies(self, saved_query_name: str) -> SavedQueryDependencySet: + if self._query_parser is None: + logger.warning( + "Trying to resolve the dependencies of a saved query when the provided semantic manifest does not " + "contain semantic models is unexpected. Returning an empty set." + ) + return SavedQueryDependencySet(()) + parse_result = self._query_parser.parse_and_validate_saved_query( saved_query_parameter=SavedQueryParameter(saved_query_name), where_filter=None, diff --git a/metricflow-semantics/tests_metricflow_semantics/api/v0_1/test_saved_query_dependency_resolver.py b/metricflow-semantics/tests_metricflow_semantics/api/v0_1/test_saved_query_dependency_resolver.py index d8514db27e..c4764ed930 100644 --- a/metricflow-semantics/tests_metricflow_semantics/api/v0_1/test_saved_query_dependency_resolver.py +++ b/metricflow-semantics/tests_metricflow_semantics/api/v0_1/test_saved_query_dependency_resolver.py @@ -1,6 +1,7 @@ from __future__ import annotations import pytest +from dbt_semantic_interfaces.implementations.project_configuration import PydanticProjectConfiguration from dbt_semantic_interfaces.implementations.semantic_manifest import ( PydanticSemanticManifest, ) @@ -23,3 +24,14 @@ def test_saved_query_dependency_resolver(resolver: SavedQueryDependencyResolver) SemanticModelReference(semantic_model_name="bookings_source"), SemanticModelReference(semantic_model_name="listings_latest"), ) + + +def test_empty_manifest() -> None: # noqa: D103 + """In case the manifest is empty, checks that the resolver can be created.""" + SavedQueryDependencyResolver( + PydanticSemanticManifest( + semantic_models=[], + metrics=[], + project_configuration=PydanticProjectConfiguration(), + ) + )