|
| 1 | +{# |
| 2 | + Inverse of PII protection: when enable_samples_on_show_sample_rows_tags is true, |
| 3 | + samples are hidden by default and only shown when the show_sample_rows tag is present. |
| 4 | + |
| 5 | + Checks three levels in order: model → test → column (test's target column only). |
| 6 | + Returns true if any level has a matching show_sample_rows tag. |
| 7 | +
|
| 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. |
| 11 | +
|
| 12 | + All tag matching is case-insensitive (tags are normalized to lowercase). |
| 13 | +#} |
1 | 14 | {% macro should_show_sample_rows(flattened_test) %} |
2 | 15 | {% if not elementary.get_config_var("enable_samples_on_show_sample_rows_tags") %} |
3 | 16 | {% do return(false) %} |
|
8 | 21 | {% else %} {% set show_tags = (raw_show_tags or []) | map("lower") | list %} |
9 | 22 | {% endif %} |
10 | 23 |
|
11 | | - {# Resolve PII tags once — only relevant when PII hiding is also enabled #} |
| 24 | + {# |
| 25 | + Resolve PII tags once upfront. We use `is string` (not `is iterable`) because |
| 26 | + strings are iterable in Jinja — iterating a string gives individual characters. |
| 27 | + #} |
12 | 28 | {% set check_pii = elementary.get_config_var("disable_samples_on_pii_tags") %} |
13 | 29 | {% if check_pii %} |
14 | 30 | {% set raw_pii_tags = elementary.get_config_var("pii_tags") %} |
|
18 | 34 | {% else %} {% set pii_tags = [] %} |
19 | 35 | {% endif %} |
20 | 36 |
|
21 | | - {# Model-level check #} |
| 37 | + {# Model-level: show_sample_rows on the model applies to all its tests #} |
22 | 38 | {% set raw_model_tags = elementary.insensitive_get_dict_value( |
23 | 39 | flattened_test, "model_tags", [] |
24 | 40 | ) %} |
25 | 41 | {% if raw_model_tags is string %} {% set model_tags = [raw_model_tags | lower] %} |
26 | 42 | {% else %} {% set model_tags = (raw_model_tags or []) | map("lower") | list %} |
27 | 43 | {% endif %} |
28 | 44 | {% if elementary.lists_intersection(model_tags, show_tags) | length > 0 %} |
| 45 | + {# PII on the model takes precedence over show_sample_rows on the same model #} |
29 | 46 | {% if check_pii and elementary.lists_intersection( |
30 | 47 | model_tags, pii_tags |
31 | 48 | ) | length > 0 %} |
|
34 | 51 | {% do return(true) %} |
35 | 52 | {% endif %} |
36 | 53 |
|
37 | | - {# Test-level check #} |
| 54 | + {# Test-level: show_sample_rows on the test definition itself #} |
38 | 55 | {% set raw_test_tags = elementary.insensitive_get_dict_value( |
39 | 56 | flattened_test, "tags", [] |
40 | 57 | ) %} |
41 | 58 | {% if raw_test_tags is string %} {% set test_tags = [raw_test_tags | lower] %} |
42 | 59 | {% else %} {% set test_tags = (raw_test_tags or []) | map("lower") | list %} |
43 | 60 | {% endif %} |
44 | 61 | {% if elementary.lists_intersection(test_tags, show_tags) | length > 0 %} |
| 62 | + {# If the model itself is PII-tagged, respect that even for test-level overrides #} |
45 | 63 | {% if check_pii and elementary.lists_intersection( |
46 | 64 | model_tags, pii_tags |
47 | 65 | ) | length > 0 %} |
|
50 | 68 | {% do return(true) %} |
51 | 69 | {% endif %} |
52 | 70 |
|
53 | | - {# Column-level check: only the test's target column #} |
| 71 | + {# |
| 72 | + Column-level: only checks the specific column the test targets (test_column_name), |
| 73 | + not all columns on the model. This avoids showing samples for unrelated columns. |
| 74 | + #} |
54 | 75 | {% set test_column_name = elementary.insensitive_get_dict_value( |
55 | 76 | flattened_test, "test_column_name" |
56 | 77 | ) %} |
|
67 | 88 | {% if elementary.lists_intersection( |
68 | 89 | col_tags, show_tags |
69 | 90 | ) | length > 0 %} |
| 91 | + {# PII on the column takes precedence over show_sample_rows on the same column #} |
70 | 92 | {% if check_pii and elementary.lists_intersection( |
71 | 93 | col_tags, pii_tags |
72 | 94 | ) | length > 0 %} |
|
0 commit comments