Skip to content

Commit 32c683c

Browse files
authored
Fix time spine validation error (#354)
### Description In my last PR, I removed an early return statement [here](https://github.com/dbt-labs/dbt-semantic-interfaces/pull/353/files#diff-23094b690ea30acfa70bbe8b29789680bc46582dfcc3c56ce1e8ce929d62781eL42). This introduced a bug when users hadn't defined a time_spine configuration. This bug wasn't released. I noticed it in my testing. ### Checklist - [x] I have read [the contributing guide](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md) and understand what's expected of me - [x] I have signed the [CLA](https://docs.getdbt.com/docs/contributor-license-agreements) - [x] This PR includes tests, or tests are not required/relevant for this PR - [x] I have run `changie new` to [create a changelog entry](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md#adding-a-changelog-entry)
1 parent c77db7a commit 32c683c

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Fixes
2+
body: Fix time spine validation error
3+
time: 2024-10-10T14:23:29.392029-05:00
4+
custom:
5+
Author: DevonFulcher
6+
Issue: None

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# dbt-semantic-interfaces
1212

13-
This repo contains the shared semantic classes, default validation, and tests designed to be used by both the dbt-core and MetricFlow projects. By centralizing these shared resources, we aim to maintain consistency and reduce code duplication across both projects.
13+
This repo contains the shared semantic classes, default validation, and tests designed to be used by both the dbt-core and MetricFlow projects. By centralizing these shared resources, we aim to maintain consistency and reduce code duplication across both projects.
1414

1515
## Features
1616
- Protocols for shared semantic classes: Define the interfaces and common attributes that must be implemented by the objects in both projects.

dbt_semantic_interfaces/validations/time_spines.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ def validate_manifest(semantic_manifest: SemanticManifestT) -> Sequence[Validati
2828
if not semantic_manifest.semantic_models:
2929
return issues
3030

31+
time_spines = semantic_manifest.project_configuration.time_spines
32+
if not time_spines:
33+
return issues
34+
3135
# Verify that there is only one time spine per granularity
3236
time_spines_by_granularity: Dict[TimeGranularity, List[TimeSpine]] = {}
3337
granularities_with_multiple_time_spines: Set[TimeGranularity] = set()
34-
for time_spine in semantic_manifest.project_configuration.time_spines:
38+
for time_spine in time_spines:
3539
granularity = time_spine.primary_column.time_granularity
3640
if granularity in time_spines_by_granularity:
3741
time_spines_by_granularity[granularity].append(time_spine)

tests/validations/test_time_spines.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,42 @@ def test_no_warning_for_legacy_time_spine() -> None: # noqa: D
127127
assert len(issues.warnings) == 0
128128

129129

130+
def test_no_time_spine_config() -> None: # noqa: D
131+
validator = SemanticManifestValidator[PydanticSemanticManifest]()
132+
semantic_manifest = PydanticSemanticManifest(
133+
semantic_models=[
134+
semantic_model_with_guaranteed_meta(
135+
name="sum_measure",
136+
dimensions=[
137+
PydanticDimension(
138+
name="dim",
139+
type=DimensionType.TIME,
140+
description="",
141+
metadata=None,
142+
type_params=PydanticDimensionTypeParams(time_granularity=TimeGranularity.SECOND),
143+
)
144+
],
145+
entities=[PydanticEntity(name="entity", type=EntityType.PRIMARY)],
146+
),
147+
],
148+
metrics=[
149+
PydanticMetric(
150+
name="metric",
151+
description=None,
152+
type=MetricType.SIMPLE,
153+
type_params=PydanticMetricTypeParams(measure=PydanticMetricInputMeasure(name="sum_measure")),
154+
),
155+
],
156+
project_configuration=PydanticProjectConfiguration(
157+
time_spine_table_configurations=[],
158+
time_spines=[],
159+
),
160+
)
161+
issues = validator.validate_semantic_manifest(semantic_manifest)
162+
assert not issues.has_blocking_issues
163+
assert len(issues.warnings) == 0
164+
165+
130166
def test_duplicate_time_spine_granularity() -> None: # noqa: D
131167
validator = SemanticManifestValidator[PydanticSemanticManifest]()
132168
semantic_manifest = PydanticSemanticManifest(

0 commit comments

Comments
 (0)