Skip to content

Commit 19f2367

Browse files
joostboonclaude
andcommitted
fix: address review findings in show_sample_rows and PII macros
- Restructure empty elif branch in test.sql with explicit comments - Column-level show_sample_rows now checks model-level PII tags too - Add explicit parens for Jinja operator precedence in get_pii_columns - Replace 'is iterable' with 'is string' guard in is_pii_table.sql (strings are iterable in Jinja, causing single tags to be split) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 77e5034 commit 19f2367

4 files changed

Lines changed: 24 additions & 28 deletions

File tree

macros/edr/materializations/test/test.sql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,17 @@
8686
4. PII tag detection (model/test/column) — hide when disable_samples_on_pii_tags
8787
is true and a PII tag is detected at any level.
8888
#}
89-
{% if disable_test_samples %} {% set sample_limit = 0 %}
89+
{% if disable_test_samples %}
90+
{% set sample_limit = 0 %}
9091
{% elif elementary.should_show_sample_rows(flattened_test) %}
92+
{# Tag explicitly opts in — keep sample_limit as-is #}
9193
{% elif elementary.get_config_var("enable_samples_on_show_sample_rows_tags") %}
94+
{# Feature is on but no show_sample_rows tag found — hide by default #}
95+
{% set sample_limit = 0 %}
96+
{% elif elementary.is_pii_table(flattened_test) %}
97+
{% set sample_limit = 0 %}
98+
{% elif elementary.is_pii_test(flattened_test) %}
9299
{% set sample_limit = 0 %}
93-
{% elif elementary.is_pii_table(flattened_test) %} {% set sample_limit = 0 %}
94-
{% elif elementary.is_pii_test(flattened_test) %} {% set sample_limit = 0 %}
95100
{% elif elementary.should_disable_sampling_for_pii(flattened_test) %}
96101
{% set sample_limit = 0 %}
97102
{% endif %}

macros/edr/system/system_utils/get_pii_columns_from_parent_model.sql

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,10 @@
5858
{# Skip column from PII list only if show_sample_rows is set and pii is not #}
5959
{% set has_show_tag = (
6060
enable_show_tags
61-
and elementary.lists_intersection(
62-
all_column_tags_lower, show_tags
63-
)
64-
| length
65-
> 0
61+
and (elementary.lists_intersection(all_column_tags_lower, show_tags) | length > 0)
6662
) %}
6763
{% set has_pii_tag = (
68-
elementary.lists_intersection(all_column_tags_lower, pii_tags)
69-
| length
70-
> 0
64+
elementary.lists_intersection(all_column_tags_lower, pii_tags) | length > 0
7165
) %}
7266
{% if has_show_tag and not has_pii_tag %} {% continue %} {% endif %}
7367

macros/edr/system/system_utils/is_pii_table.sql

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@
55
{% if not disable_samples_on_pii_tags %} {% do return(false) %} {% endif %}
66

77
{% set raw_pii_tags = elementary.get_config_var("pii_tags") %}
8-
{% set pii_tags = (
9-
(raw_pii_tags if raw_pii_tags is iterable else [raw_pii_tags])
10-
| map("lower")
11-
| list
12-
) %}
8+
{% if raw_pii_tags is string %} {% set pii_tags = [raw_pii_tags | lower] %}
9+
{% else %} {% set pii_tags = (raw_pii_tags or []) | map("lower") | list %}
10+
{% endif %}
1311

1412
{% set raw_model_tags = elementary.insensitive_get_dict_value(
1513
flattened_test, "model_tags", []
1614
) %}
17-
{% set model_tags = (
18-
(raw_model_tags if raw_model_tags is iterable else [raw_model_tags])
19-
| map("lower")
20-
| list
21-
) %}
15+
{% if raw_model_tags is string %} {% set model_tags = [raw_model_tags | lower] %}
16+
{% else %} {% set model_tags = (raw_model_tags or []) | map("lower") | list %}
17+
{% endif %}
2218

2319
{% set intersection = elementary.lists_intersection(model_tags, pii_tags) %}
2420
{% set is_pii = intersection | length > 0 %}

macros/edr/system/system_utils/should_show_sample_rows.sql

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
Checks three levels in order: model → test → column (test's target column only).
66
Returns true if any level has a matching show_sample_rows tag.
77
8-
PII precedence: if disable_samples_on_pii_tags is also enabled and the same
9-
model/column has a PII tag, PII wins and this returns false. This handles the
10-
edge case where both features are active simultaneously.
8+
PII precedence: if disable_samples_on_pii_tags is also enabled and the model
9+
or column has a PII tag, PII wins and this returns false. A model-level PII
10+
tag blocks show_sample_rows at every level (model, test, and column).
1111
1212
All tag matching is case-insensitive (tags are normalized to lowercase).
1313
#}
@@ -88,10 +88,11 @@
8888
{% if elementary.lists_intersection(
8989
col_tags, show_tags
9090
) | length > 0 %}
91-
{# PII on the column takes precedence over show_sample_rows on the same column #}
92-
{% if check_pii and elementary.lists_intersection(
93-
col_tags, pii_tags
94-
) | length > 0 %}
91+
{# PII on the column or model takes precedence over show_sample_rows #}
92+
{% if check_pii and (
93+
elementary.lists_intersection(col_tags, pii_tags) | length > 0
94+
or elementary.lists_intersection(model_tags, pii_tags) | length > 0
95+
) %}
9596
{% do return(false) %}
9697
{% endif %}
9798
{% do return(true) %}

0 commit comments

Comments
 (0)