From 4a88879869cecc6125f8077c1163a46c61eee79f Mon Sep 17 00:00:00 2001 From: Antonio Papa Date: Mon, 22 Apr 2024 08:28:45 -0400 Subject: [PATCH 1/2] Allows a snapshot to have a list as a unique_key --- core/dbt/artifacts/resources/v1/snapshot.py | 2 +- core/dbt/contracts/graph/model_config.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/dbt/artifacts/resources/v1/snapshot.py b/core/dbt/artifacts/resources/v1/snapshot.py index 3eceb9bb1d2..4c9cbea27c5 100644 --- a/core/dbt/artifacts/resources/v1/snapshot.py +++ b/core/dbt/artifacts/resources/v1/snapshot.py @@ -10,11 +10,11 @@ class SnapshotConfig(NodeConfig): materialized: str = "snapshot" strategy: Optional[str] = None - unique_key: Optional[str] = None target_schema: Optional[str] = None target_database: Optional[str] = None updated_at: Optional[str] = None # Not using Optional because of serialization issues with a Union of str and List[str] + unique_key: Union[str, List[str], None] = None check_cols: Union[str, List[str], None] = None @classmethod diff --git a/core/dbt/contracts/graph/model_config.py b/core/dbt/contracts/graph/model_config.py index b45c313327c..8181f8b34bd 100644 --- a/core/dbt/contracts/graph/model_config.py +++ b/core/dbt/contracts/graph/model_config.py @@ -1,5 +1,5 @@ from dataclasses import field, dataclass -from typing import Any, List, Optional, Dict, Type +from typing import Any, List, Optional, Dict, Type, Union from dbt.artifacts.resources import ( ExposureConfig, @@ -42,7 +42,7 @@ class UnitTestNodeConfig(NodeConfig): @dataclass class EmptySnapshotConfig(NodeConfig): materialized: str = "snapshot" - unique_key: Optional[str] = None # override NodeConfig unique_key definition + unique_key: Union[str, List[str], None] = None # override NodeConfig unique_key definition RESOURCE_TYPES: Dict[NodeType, Type[BaseConfig]] = { From b25f28f7afb2e5e99485e478c9d5ea11e67082fd Mon Sep 17 00:00:00 2001 From: Antonio Papa Date: Mon, 22 Apr 2024 08:29:37 -0400 Subject: [PATCH 2/2] Adds changie --- .changes/unreleased/Features-20240422-082925.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Features-20240422-082925.yaml diff --git a/.changes/unreleased/Features-20240422-082925.yaml b/.changes/unreleased/Features-20240422-082925.yaml new file mode 100644 index 00000000000..b2e029fcf38 --- /dev/null +++ b/.changes/unreleased/Features-20240422-082925.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Allows snapshots to take a list as a unique_key +time: 2024-04-22T08:29:25.458309-04:00 +custom: + Author: agpapa + Issue: "9992"