Skip to content
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

Remove cumulative metric type param deprecation warning #356

Merged
Merged
Show file tree
Hide file tree
Changes from 7 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
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20241010-164927.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Downgrade Pydantic in dev-env
time: 2024-10-10T16:49:27.844308-05:00
custom:
Author: DevonFulcher
Issue: None
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20241015-110006.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Remove cumulative metric type param deprecation warning
time: 2024-10-15T11:00:06.108655-05:00
custom:
Author: DevonFulcher
Issue: None
19 changes: 1 addition & 18 deletions dbt_semantic_interfaces/validations/metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import traceback
from typing import Dict, Generic, List, Optional, Sequence, Set, Tuple
from typing import Dict, Generic, List, Optional, Sequence, Tuple

from dbt_semantic_interfaces.call_parameter_sets import FilterCallParameterSets
from dbt_semantic_interfaces.errors import ParsingException
Expand Down Expand Up @@ -48,7 +48,6 @@ class CumulativeMetricRule(SemanticManifestValidationRule[SemanticManifestT], Ge
def validate_manifest(semantic_manifest: SemanticManifestT) -> Sequence[ValidationIssue]: # noqa: D
issues: List[ValidationIssue] = []

metrics_using_old_params: Set[str] = set()
for metric in semantic_manifest.metrics or []:
if metric.type != MetricType.CUMULATIVE:
continue
Expand All @@ -60,9 +59,6 @@ def validate_manifest(semantic_manifest: SemanticManifestT) -> Sequence[Validati

for field in ("window", "grain_to_date"):
type_params_field_value = getattr(metric.type_params, field)
# Warn that the old type_params structure has been deprecated.
if type_params_field_value:
metrics_using_old_params.add(metric.name)

# Warn that window or grain_to_date is mismatched across params.
cumulative_type_params_field_value = (
Expand Down Expand Up @@ -115,19 +111,6 @@ def validate_manifest(semantic_manifest: SemanticManifestT) -> Sequence[Validati
extra_detail="".join(traceback.format_tb(e.__traceback__)),
)
)
if metrics_using_old_params:
issues.append(
ValidationWarning(
context=metric_context,
message=(
"Cumulative fields `type_params.window` and `type_params.grain_to_date` have been moved and "
"will soon be deprecated. Please nest those values under "
"`type_params.cumulative_type_params.window` and "
"`type_params.cumulative_type_params.grain_to_date`. Metrics using old fields: "
f"{sorted(metrics_using_old_params)}"
),
)
)

return issues

Expand Down
10 changes: 10 additions & 0 deletions dsi_pydantic_shim.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
"""Shim to allow support for both Pydantic 1 and Pydantic 2.

DSI must support both major versions of Pydantic because dbt-core depends on DSI. dbt-core users might be using an
environment with either version, and we can't restrict them to one or the other. Here, we essentially import all
Pydantic objects from version 1. Throughout the repo, we import those objects from this file instead of from Pydantic
directly, meaning that we essentially only use Pydantic 1 in this repo, but without forcing that restriction on dbt
users. The development environment for this repo should be pinned to Pydantic 1 to ensure devs get appropriate type
hints.
"""

from importlib.metadata import version

pydantic_version = version("pydantic")
Expand Down
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ readme = "README.md"
requires-python = ">=3.8"
license = "Apache-2.0"
keywords = []
authors = [
{ name = "dbt Labs", email = "[email protected]" },
]
authors = [{ name = "dbt Labs", email = "[email protected]" }]
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: Apache Software License",
Expand Down Expand Up @@ -66,7 +64,8 @@ dependencies = [
"isort>=5.12,<6",
"black>=23.3,<24",
"ruff==0.0.260",
"mypy>=1.3,<2",
"mypy==1.6.1",
"pydantic>=1.10,<2", # The types in this codebase with mypy checker are only compatible with pydantic 1
"pytest>=7.3,<8",
"types-Jinja2>=2.11,<3",
"types-jsonschema>=4.17,<5",
Expand All @@ -86,7 +85,7 @@ ignore = [
# Missing docstring in public module -- often docs handled within classes
"D100",
# Missing docstring in public package -- often docs handled within files not __init__.py
"D104"
"D104",
]
# Let ruff autofix these errors.
# F401 - Unused imports.
Expand Down
10 changes: 5 additions & 5 deletions tests/validations/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ def check_error_in_issues(error_substrings: List[str], issues: Tuple[ValidationI
for expected_str in error_substrings:
if not any(actual_str.as_readable_str().find(expected_str) != -1 for actual_str in issues):
missing_error_strings.add(expected_str)
assert len(missing_error_strings) == 0, "Failed to match one or more expected issues: "
f"{missing_error_strings} in {set([x.as_readable_str() for x in issues])}"
assert len(missing_error_strings) == 0, (
"Failed to match one or more expected issues: "
+ f"{missing_error_strings} in {set([x.as_readable_str() for x in issues])}"
)


def test_metric_no_time_dim_dim_only_source() -> None: # noqa:D
Expand Down Expand Up @@ -742,13 +744,11 @@ def test_cumulative_metrics() -> None: # noqa: D
)

build_issues = validation_results.all_issues
assert len(build_issues) == 4
assert len(build_issues) == 3
expected_substrings = [
"Both window and grain_to_date set for cumulative metric. Please set one or the other.",
"Got differing values for `window`",
"Got differing values for `grain_to_date`",
"Cumulative fields `type_params.window` and `type_params.grain_to_date` have been moved",
str(sorted({"what_a_metric", "dis_bad", "woooooo", "metric1", "metric2"})),
]
check_error_in_issues(error_substrings=expected_substrings, issues=build_issues)

Expand Down
Loading