From 4a052468fb3777a970887978aa4f64fd4b56ba41 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Wed, 18 Dec 2024 14:24:27 -0500 Subject: [PATCH] Fix yaml snapshot specification with data tests (#11156) (cherry picked from commit 6076cf7114e6ce0cfb10e4c0f371a6dc1c13eb20) --- .changes/unreleased/Fixes-20241216-134645.yaml | 6 ++++++ core/dbt/parser/schemas.py | 9 ++++++++- tests/functional/snapshots/fixtures.py | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Fixes-20241216-134645.yaml diff --git a/.changes/unreleased/Fixes-20241216-134645.yaml b/.changes/unreleased/Fixes-20241216-134645.yaml new file mode 100644 index 00000000000..2ef41dc0d2d --- /dev/null +++ b/.changes/unreleased/Fixes-20241216-134645.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Error writing generic test at run time +time: 2024-12-16T13:46:45.936573-05:00 +custom: + Author: gshank + Issue: "11110" diff --git a/core/dbt/parser/schemas.py b/core/dbt/parser/schemas.py index 12bb84a5037..e9c66e184e4 100644 --- a/core/dbt/parser/schemas.py +++ b/core/dbt/parser/schemas.py @@ -1,4 +1,5 @@ import datetime +import pathlib import time from abc import ABCMeta, abstractmethod from dataclasses import dataclass, field @@ -289,9 +290,15 @@ def _add_yaml_snapshot_nodes_to_manifest( parser = SnapshotParser(self.project, self.manifest, self.root_project) fqn = parser.get_fqn_prefix(block.path.relative_path) fqn.append(snapshot["name"]) + + compiled_path = str( + pathlib.PurePath("").joinpath( + block.path.relative_path, snapshot["name"] + ".sql" + ) + ) snapshot_node = parser._create_parsetime_node( block, - self.get_compiled_path(block), + compiled_path, parser.initial_config(fqn), fqn, snapshot["name"], diff --git a/tests/functional/snapshots/fixtures.py b/tests/functional/snapshots/fixtures.py index 562fcb4b10f..df0c29b8fa5 100644 --- a/tests/functional/snapshots/fixtures.py +++ b/tests/functional/snapshots/fixtures.py @@ -301,6 +301,10 @@ updated_at: updated_at meta: owner: 'a_owner' + columns: + - name: id + data_tests: + - not_null """ snapshots_pg__snapshot_mod_yml = """ @@ -313,6 +317,10 @@ updated_at: updated_at meta: owner: 'b_owner' + columns: + - name: id + data_tests: + - not_null """ snapshots_pg__snapshot_no_target_schema_sql = """