From 136fb41cfb4c5b01195ac7b389a1eb621c360924 Mon Sep 17 00:00:00 2001 From: tlento Date: Tue, 3 Sep 2024 13:50:56 -0700 Subject: [PATCH] Change assertions to warnings for evaluation. --- .../model/semantics/semantic_model_lookup.py | 10 ++++++---- .../specs/non_additive_dimension_spec.py | 13 +++++++++---- .../dataflow/builder/dataflow_plan_builder.py | 10 ++++++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/model/semantics/semantic_model_lookup.py b/metricflow-semantics/metricflow_semantics/model/semantics/semantic_model_lookup.py index 1277cae9a2..df32102085 100644 --- a/metricflow-semantics/metricflow_semantics/model/semantics/semantic_model_lookup.py +++ b/metricflow-semantics/metricflow_semantics/model/semantics/semantic_model_lookup.py @@ -242,10 +242,12 @@ def _add_semantic_model(self, semantic_model: SemanticModel) -> None: semantic_models_for_dimension = self._dimension_index.get(dim.reference, []) + [semantic_model] self._dimension_index[dim.reference] = semantic_models_for_dimension - assert StructuredLinkableSpecName.from_name(dim.name).is_element_name, ( - f"Dimension name `{dim.name}` contains annotations, but this name should be the plain element name " - "from the original model. This should have been blocked by validation!" - ) + if not StructuredLinkableSpecName.from_name(dim.name).is_element_name: + # TODO: [custom granularity] change this to an assertion once we're sure there aren't exceptions + logger.warning( + f"Dimension name `{dim.name}` contains annotations, but this name should be the plain element name " + "from the original model. This should have been blocked by validation!" + ) # TODO: Construct these specs correctly. All of the time dimension specs have the default granularity self._dimension_ref_to_spec[dim.time_dimension_reference or dim.reference] = ( diff --git a/metricflow-semantics/metricflow_semantics/specs/non_additive_dimension_spec.py b/metricflow-semantics/metricflow_semantics/specs/non_additive_dimension_spec.py index 78eb3df0ff..0e09b5a548 100644 --- a/metricflow-semantics/metricflow_semantics/specs/non_additive_dimension_spec.py +++ b/metricflow-semantics/metricflow_semantics/specs/non_additive_dimension_spec.py @@ -1,5 +1,6 @@ from __future__ import annotations +import logging from dataclasses import dataclass from hashlib import sha1 from typing import Any, Sequence, Tuple @@ -13,6 +14,8 @@ from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec from metricflow_semantics.sql.sql_column_type import SqlColumnType +logger = logging.getLogger(__file__) + def hash_items(items: Sequence[SqlColumnType]) -> str: """Produces a hash from a list of strings.""" @@ -36,10 +39,12 @@ class NonAdditiveDimensionSpec(SerializableDataclass): def __post_init__(self) -> None: """Post init validator to ensure names with double-underscores are not allowed.""" - assert self.name.find(DUNDER) == -1, ( - f"Non-additive dimension spec references a dimension name `{self.name}`, with added annotations, but it " - "should be a simple element name reference. This should have been blocked by model validation!" - ) + # TODO: [custom granularity] change this to an assertion once we're sure there aren't exceptions + if not self.name.find(DUNDER) == -1: + logger.warning( + f"Non-additive dimension spec references a dimension name `{self.name}`, with added annotations, but it " + "should be a simple element name reference. This should have been blocked by model validation!" + ) @property def bucket_hash(self) -> str: diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index a0477f857a..9f972fe51f 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -401,10 +401,12 @@ def _build_conversion_metric_output_node( descendent_filter_specs=metric_spec.filter_specs, queried_linkable_specs=queried_linkable_specs, ) - assert StructuredLinkableSpecName.from_name(conversion_type_params.entity).is_element_name, ( - f"Found additional annotations in type param entity name `{conversion_type_params.entity}`, which should " - "be a simple element name reference. This should have been blocked by model validation!" - ) + # TODO: [custom granularity] change this to an assertion once we're sure there aren't exceptions + if not StructuredLinkableSpecName.from_name(conversion_type_params.entity).is_element_name: + logger.warning( + f"Found additional annotations in type param entity name `{conversion_type_params.entity}`, which " + "should be a simple element name reference. This should have been blocked by model validation!" + ) entity_spec = EntitySpec(element_name=conversion_type_params.entity, entity_links=()) logger.info( f"For conversion metric {metric_spec},\n"