Skip to content

Backport updated error message for missing time spine #1707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ def build_standard_time_spine_sources(
base_granularity=legacy_time_spine.grain,
)

# Sanity check: this should have been validated during manifest parsing.
if not time_spine_sources:
raise RuntimeError(
"At least one time spine must be configured to use the semantic layer, but none were found."
)

return time_spine_sources

@staticmethod
Expand Down
33 changes: 33 additions & 0 deletions tests_metricflow/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration

from dbt_metricflow.cli.cli_configuration import CLIConfiguration
from dbt_metricflow.cli.tutorial import dbtMetricFlowTutorialHelper
from tests_metricflow.cli.cli_test_helpers import (
create_tutorial_project_files,
run_and_check_cli_command,
Expand Down Expand Up @@ -352,3 +353,35 @@ def test_csv(
snapshot_str=csv_file_contents,
expectation_description="A CSV file containing the values for 2 metrics.",
)


@pytest.mark.slow
def test_missing_time_spine_error(
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
) -> None:
"""Test the error message that a user gets when a time spine is not configured in the project."""
with tempfile.TemporaryDirectory() as tmp_directory:
tmp_directory_path = Path(tmp_directory)
dbt_project_path = tmp_directory_path / "mf_tutorial_project"
dbtMetricFlowTutorialHelper.generate_dbt_project(dbt_project_path)

model_yaml_file_path = dbt_project_path / "models" / "_models.yml"
Path.unlink(model_yaml_file_path)
logger.debug(LazyFormat("Removed time spine model file", model_yaml_file_path=model_yaml_file_path))

cli_runner = IsolatedCliCommandRunner(
dbt_profiles_path=dbt_project_path,
dbt_project_path=dbt_project_path,
)
with cli_runner.running_context():
run_dbt_build(cli_runner)

run_and_check_cli_command(
request=request,
mf_test_configuration=mf_test_configuration,
cli_runner=cli_runner,
command_enum=IsolatedCliCommandEnum.MF_LIST,
args=["metrics"],
expected_exit_code=1,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
test_name: test_missing_time_spine_error
test_filename: test_cli.py
docstring:
Test the error message that a user gets when a time spine is not configured in the project.
---

ERROR: At least one time spine must be configured to use the semantic layer, but none were found.

Log File: ***
Artifact Path: ***
Artifact Modified Time: ***

If you think you found a bug, please report it here:
https://github.com/dbt-labs/metricflow/issues