|
13 | 13 | # permissions and limitations under the License. |
14 | 14 |
|
15 | 15 |
|
| 16 | +import os |
16 | 17 | from typing import Annotated, Tuple |
17 | 18 |
|
18 | 19 | import pytest |
19 | 20 |
|
20 | 21 | from zenml import ArtifactConfig, Tag, add_tags, pipeline, remove_tags, step |
| 22 | +from zenml.constants import ENV_ZENML_PREVENT_CLIENT_SIDE_CACHING |
| 23 | +from zenml.enums import ExecutionStatus |
21 | 24 |
|
22 | 25 |
|
23 | 26 | @step |
@@ -139,3 +142,101 @@ def test_tag_utils(clean_client): |
139 | 142 | clean_client.update_tag( |
140 | 143 | tag_name_or_id=non_exclusive_tag.id, exclusive=True |
141 | 144 | ) |
| 145 | + |
| 146 | + |
| 147 | +@pipeline( |
| 148 | + tags=[Tag(name="cascade_tag", cascade=True)], |
| 149 | + enable_cache=False, |
| 150 | +) |
| 151 | +def pipeline_with_cascade_tag(): |
| 152 | + """Pipeline definition to test the tag utils.""" |
| 153 | + _ = step_single_output() |
| 154 | + |
| 155 | + |
| 156 | +def test_cascade_tags_for_output_artifacts_of_cached_pipeline_run( |
| 157 | + clean_client, |
| 158 | +): |
| 159 | + """Test that the cascade tags are added to the output artifacts of a cached step.""" |
| 160 | + # Run the pipeline once without caching |
| 161 | + pipeline_with_cascade_tag() |
| 162 | + |
| 163 | + pipeline_runs = clean_client.list_pipeline_runs(sort_by="created") |
| 164 | + assert len(pipeline_runs.items) == 1 |
| 165 | + assert ( |
| 166 | + pipeline_runs.items[0].steps["step_single_output"].status |
| 167 | + == ExecutionStatus.COMPLETED |
| 168 | + ) |
| 169 | + assert "cascade_tag" in [ |
| 170 | + t.name |
| 171 | + for t in pipeline_runs.items[0] |
| 172 | + .steps["step_single_output"] |
| 173 | + .outputs["single"][0] |
| 174 | + .tags |
| 175 | + ] |
| 176 | + |
| 177 | + # Run it once again with caching |
| 178 | + pipeline_with_cascade_tag.configure(enable_cache=True) |
| 179 | + pipeline_with_cascade_tag() |
| 180 | + pipeline_runs = clean_client.list_pipeline_runs(sort_by="created") |
| 181 | + assert len(pipeline_runs.items) == 2 |
| 182 | + assert ( |
| 183 | + pipeline_runs.items[1].steps["step_single_output"].status |
| 184 | + == ExecutionStatus.CACHED |
| 185 | + ) |
| 186 | + |
| 187 | + # Run it once again with caching and a new cascade tag |
| 188 | + pipeline_with_cascade_tag.configure( |
| 189 | + tags=[Tag(name="second_cascade_tag", cascade=True)] |
| 190 | + ) |
| 191 | + pipeline_with_cascade_tag() |
| 192 | + pipeline_runs = clean_client.list_pipeline_runs(sort_by="created") |
| 193 | + assert len(pipeline_runs.items) == 3 |
| 194 | + assert ( |
| 195 | + pipeline_runs.items[2].steps["step_single_output"].status |
| 196 | + == ExecutionStatus.CACHED |
| 197 | + ) |
| 198 | + |
| 199 | + assert "second_cascade_tag" in [ |
| 200 | + t.name |
| 201 | + for t in pipeline_runs.items[0] |
| 202 | + .steps["step_single_output"] |
| 203 | + .outputs["single"][0] |
| 204 | + .tags |
| 205 | + ] |
| 206 | + assert "second_cascade_tag" in [ |
| 207 | + t.name |
| 208 | + for t in pipeline_runs.items[2] |
| 209 | + .steps["step_single_output"] |
| 210 | + .outputs["single"][0] |
| 211 | + .tags |
| 212 | + ] |
| 213 | + |
| 214 | + # Run it once again with caching (preventing client side caching) and a new cascade tag |
| 215 | + os.environ[ENV_ZENML_PREVENT_CLIENT_SIDE_CACHING] = "true" |
| 216 | + pipeline_with_cascade_tag.configure( |
| 217 | + tags=[Tag(name="third_cascade_tag", cascade=True)] |
| 218 | + ) |
| 219 | + pipeline_with_cascade_tag() |
| 220 | + |
| 221 | + pipeline_runs = clean_client.list_pipeline_runs(sort_by="created") |
| 222 | + assert len(pipeline_runs.items) == 4 |
| 223 | + assert ( |
| 224 | + pipeline_runs.items[3].steps["step_single_output"].status |
| 225 | + == ExecutionStatus.CACHED |
| 226 | + ) |
| 227 | + |
| 228 | + assert "third_cascade_tag" in [ |
| 229 | + t.name |
| 230 | + for t in pipeline_runs.items[0] |
| 231 | + .steps["step_single_output"] |
| 232 | + .outputs["single"][0] |
| 233 | + .tags |
| 234 | + ] |
| 235 | + assert "third_cascade_tag" in [ |
| 236 | + t.name |
| 237 | + for t in pipeline_runs.items[3] |
| 238 | + .steps["step_single_output"] |
| 239 | + .outputs["single"][0] |
| 240 | + .tags |
| 241 | + ] |
| 242 | + os.environ.pop(ENV_ZENML_PREVENT_CLIENT_SIDE_CACHING, None) |
0 commit comments