Skip to content

Commit

Permalink
Add empty manifest check for SavedQueryDependencyResolver (#1429)
Browse files Browse the repository at this point in the history
There seems to be issues with initializing `MetricflowQueryParser` with
an empty manifest. This is related to recent time spine changes, but
resolving that might take some time, so putting out this PR as a
temporary solution.
  • Loading branch information
plypaul authored Sep 25, 2024
1 parent 488a694 commit b19a24d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
Expand All @@ -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(),
)
)

0 comments on commit b19a24d

Please sign in to comment.