Skip to content

Commit

Permalink
Ensure lowercasing for grain_to_date and offset_to_grain
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Nov 26, 2024
1 parent 2083a24 commit 00abab6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion dbt_semantic_interfaces/implementations/metric.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Dict, List, Optional, Sequence, Set
from copy import deepcopy
from typing import Any, Dict, List, Optional, Sequence, Set

from typing_extensions import override

Expand Down Expand Up @@ -222,6 +223,26 @@ def _implements_protocol(self) -> Metric: # noqa: D
config: Optional[PydanticSemanticLayerElementConfig]
time_granularity: Optional[str] = None

@classmethod
def parse_obj(cls, input: Any) -> PydanticMetric:
data = deepcopy(input)

# Ensure grain_to_date is lowercased
type_params = data.get("type_params", {})
grain_to_date = type_params.get("cumulative_type_params", {}).get("grain_to_date")
if isinstance(grain_to_date, str):
data["type_params"]["cumulative_type_params"]["grain_to_date"] = grain_to_date.lower()

# Ensure offset_to_grain is lowercased
input_metrics = type_params.get("metrics", [])
if input_metrics:
for input_metric in input_metrics:
offset_to_grain = input_metric.get("offset_to_grain")
if offset_to_grain and isinstance(offset_to_grain, str):
input_metric["offset_to_grain"] = offset_to_grain.lower()

return super(HashableBaseModel, cls).parse_obj(data)

@property
def input_measures(self) -> Sequence[PydanticMetricInputMeasure]:
"""Return the complete list of input measure configurations for this metric."""
Expand Down

0 comments on commit 00abab6

Please sign in to comment.