From 7e3c6b1081b8c11bf8c58dd875ba46aa371becd6 Mon Sep 17 00:00:00 2001 From: Joost Boonzajer Flaes Date: Tue, 7 Apr 2026 18:08:41 +0300 Subject: [PATCH 1/2] fix: allow _with_context tests to collect sample rows Elementary-namespaced tests were early-returning from the test materialization, bypassing all sampling logic. _with_context tests behave like regular dbt tests (they return failing rows) so they should go through the standard handle_dbt_test sampling path. Co-Authored-By: Claude Sonnet 4.6 --- macros/edr/materializations/test/test.sql | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/macros/edr/materializations/test/test.sql b/macros/edr/materializations/test/test.sql index 71fe21d5f..db077b993 100644 --- a/macros/edr/materializations/test/test.sql +++ b/macros/edr/materializations/test/test.sql @@ -28,8 +28,11 @@ {% endif %} {% set test_namespace = model.get("test_metadata", {}).get("namespace") %} - {% if test_namespace == "elementary" %} - {# Custom test materialization is needed only for non-elementary tests #} + {% set test_name = model.get("test_metadata", {}).get("name", "") %} + {% if test_namespace == "elementary" and not test_name.endswith("_with_context") %} + {# Custom test materialization is needed only for non-elementary tests. + _with_context tests are elementary-namespaced but behave like regular dbt + tests (they return failing rows) so they go through the standard sampling path. #} {% do return(materialization_macro()) %} {% endif %} From 37988b0e577238c0c86fe2c377622602fbaf46bd Mon Sep 17 00:00:00 2001 From: Joost Boonzajer Flaes Date: Thu, 9 Apr 2026 18:19:43 +0300 Subject: [PATCH 2/2] fix: use get_elementary_test_type to gate early return in test materialization Instead of checking test name suffix, use the existing get_elementary_test_type macro to determine if an elementary-namespaced test handles its own result row collection. Only anomaly detection and schema change tests early-return; all other elementary tests (e.g. _with_context) go through the standard sampling path. Co-Authored-By: Claude Sonnet 4.6 --- macros/edr/materializations/test/test.sql | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/macros/edr/materializations/test/test.sql b/macros/edr/materializations/test/test.sql index db077b993..337f06c02 100644 --- a/macros/edr/materializations/test/test.sql +++ b/macros/edr/materializations/test/test.sql @@ -28,12 +28,15 @@ {% endif %} {% set test_namespace = model.get("test_metadata", {}).get("namespace") %} - {% set test_name = model.get("test_metadata", {}).get("name", "") %} - {% if test_namespace == "elementary" and not test_name.endswith("_with_context") %} - {# Custom test materialization is needed only for non-elementary tests. - _with_context tests are elementary-namespaced but behave like regular dbt - tests (they return failing rows) so they go through the standard sampling path. #} - {% do return(materialization_macro()) %} + {% if test_namespace == "elementary" %} + {% set short_name = model.get("test_metadata", {}).get("name", "") | lower %} + {% set elementary_test_type = elementary.get_elementary_test_type( + {"short_name": short_name, "test_namespace": "elementary"} + ) %} + {% if elementary_test_type %} + {# Anomaly detection and schema change tests handle their own result row collection #} + {% do return(materialization_macro()) %} + {% endif %} {% endif %} {% set flattened_test = elementary.flatten_test(model) %}