Skip to content

Commit dcfcb8a

Browse files
authored
Fix snapshot exclusive tagging (#4034)
* Fix exclusive tags for snapshots * Simplify adding/removing a single tag
1 parent 65c4e52 commit dcfcb8a

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

src/zenml/utils/tag_utils.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,38 +127,38 @@ def to_request(self) -> "TagRequest":
127127

128128
@overload
129129
def add_tags(
130-
tags: List[Union[str, Tag]],
130+
tags: Union[str, Tag, List[Union[str, Tag]]],
131131
) -> None: ...
132132

133133

134134
@overload
135135
def add_tags(
136136
*,
137-
tags: List[Union[str, Tag]],
137+
tags: Union[str, Tag, List[Union[str, Tag]]],
138138
run: Union[UUID, str],
139139
) -> None: ...
140140

141141

142142
@overload
143143
def add_tags(
144144
*,
145-
tags: List[Union[str, Tag]],
145+
tags: Union[str, Tag, List[Union[str, Tag]]],
146146
artifact: Union[UUID, str],
147147
) -> None: ...
148148

149149

150150
@overload
151151
def add_tags(
152152
*,
153-
tags: List[Union[str, Tag]],
153+
tags: Union[str, Tag, List[Union[str, Tag]]],
154154
artifact_version_id: UUID,
155155
) -> None: ...
156156

157157

158158
@overload
159159
def add_tags(
160160
*,
161-
tags: List[Union[str, Tag]],
161+
tags: Union[str, Tag, List[Union[str, Tag]]],
162162
artifact_name: str,
163163
artifact_version: str,
164164
) -> None: ...
@@ -167,7 +167,7 @@ def add_tags(
167167
@overload
168168
def add_tags(
169169
*,
170-
tags: List[Union[str, Tag]],
170+
tags: Union[str, Tag, List[Union[str, Tag]]],
171171
infer_artifact: bool = False,
172172
artifact_name: Optional[str] = None,
173173
) -> None: ...
@@ -176,37 +176,37 @@ def add_tags(
176176
@overload
177177
def add_tags(
178178
*,
179-
tags: List[Union[str, Tag]],
179+
tags: Union[str, Tag, List[Union[str, Tag]]],
180180
pipeline: Union[UUID, str],
181181
) -> None: ...
182182

183183

184184
@overload
185185
def add_tags(
186186
*,
187-
tags: List[Union[str, Tag]],
187+
tags: Union[str, Tag, List[Union[str, Tag]]],
188188
run_template: Union[UUID, str],
189189
) -> None: ...
190190

191191

192192
@overload
193193
def add_tags(
194194
*,
195-
tags: List[Union[str, Tag]],
195+
tags: Union[str, Tag, List[Union[str, Tag]]],
196196
snapshot: Union[UUID, str],
197197
) -> None: ...
198198

199199

200200
@overload
201201
def add_tags(
202202
*,
203-
tags: List[Union[str, Tag]],
203+
tags: Union[str, Tag, List[Union[str, Tag]]],
204204
deployment: Union[UUID, str],
205205
) -> None: ...
206206

207207

208208
def add_tags(
209-
tags: List[Union[str, Tag]],
209+
tags: Union[str, Tag, List[Union[str, Tag]]],
210210
# Pipelines
211211
pipeline: Optional[Union[UUID, str]] = None,
212212
# Runs
@@ -253,6 +253,9 @@ def add_tags(
253253
resource_id = None
254254
resource_type = None
255255

256+
if isinstance(tags, (str, Tag)):
257+
tags = [tags]
258+
256259
# Tag a pipeline
257260
if pipeline is not None and all(
258261
v is None
@@ -509,7 +512,6 @@ def add_tags(
509512
"""
510513
)
511514

512-
# Create tag resources and add tags
513515
if resource_id:
514516
for tag in tags:
515517
client.attach_tag(
@@ -520,70 +522,70 @@ def add_tags(
520522

521523
@overload
522524
def remove_tags(
523-
tags: List[str],
525+
tags: Union[str, List[str]],
524526
) -> None: ...
525527

526528

527529
@overload
528530
def remove_tags(
529531
*,
530-
tags: List[str],
532+
tags: Union[str, List[str]],
531533
pipeline: Union[UUID, str],
532534
) -> None: ...
533535

534536

535537
@overload
536538
def remove_tags(
537539
*,
538-
tags: List[str],
540+
tags: Union[str, List[str]],
539541
run: Union[UUID, str],
540542
) -> None: ...
541543

542544

543545
@overload
544546
def remove_tags(
545547
*,
546-
tags: List[str],
548+
tags: Union[str, List[str]],
547549
run_template: Union[UUID, str],
548550
) -> None: ...
549551

550552

551553
@overload
552554
def remove_tags(
553555
*,
554-
tags: List[str],
556+
tags: Union[str, List[str]],
555557
snapshot: Union[UUID, str],
556558
) -> None: ...
557559

558560

559561
@overload
560562
def remove_tags(
561563
*,
562-
tags: List[str],
564+
tags: Union[str, List[str]],
563565
deployment: Union[UUID, str],
564566
) -> None: ...
565567

566568

567569
@overload
568570
def remove_tags(
569571
*,
570-
tags: List[str],
572+
tags: Union[str, List[str]],
571573
artifact: Union[UUID, str],
572574
) -> None: ...
573575

574576

575577
@overload
576578
def remove_tags(
577579
*,
578-
tags: List[str],
580+
tags: Union[str, List[str]],
579581
artifact_version_id: UUID,
580582
) -> None: ...
581583

582584

583585
@overload
584586
def remove_tags(
585587
*,
586-
tags: List[str],
588+
tags: Union[str, List[str]],
587589
artifact_name: str,
588590
artifact_version: str,
589591
) -> None: ...
@@ -592,14 +594,14 @@ def remove_tags(
592594
@overload
593595
def remove_tags(
594596
*,
595-
tags: List[str],
597+
tags: Union[str, List[str]],
596598
infer_artifact: bool = False,
597599
artifact_name: Optional[str] = None,
598600
) -> None: ...
599601

600602

601603
def remove_tags(
602-
tags: List[str],
604+
tags: Union[str, List[str]],
603605
# Pipelines
604606
pipeline: Optional[Union[UUID, str]] = None,
605607
# Runs
@@ -645,6 +647,9 @@ def remove_tags(
645647
resource_id = None
646648
resource_type = None
647649

650+
if isinstance(tags, str):
651+
tags = [tags]
652+
648653
# Remove tags from a pipeline
649654
if pipeline is not None and all(
650655
v is None

src/zenml/zen_stores/sql_zen_store.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13841,7 +13841,7 @@ def _create_tag_resource_schemas(
1384113841
PipelineSnapshotFilter(
1384213842
id=f"notequals:{resource.id}",
1384313843
project=resource.project.id,
13844-
pipeline_id=scope_id,
13844+
pipeline=scope_id,
1384513845
tags=[tag_schema.name],
1384613846
)
1384713847
)
@@ -13884,9 +13884,8 @@ def _create_tag_resource_schemas(
1388413884
"Can not attach exclusive tag to resource of type "
1388513885
f"{resource_type.value} with ID: `{resource.id}`. "
1388613886
"Exclusive tag functionality only works for "
13887-
"templates, for pipeline runs (within the scope of "
13888-
"pipelines) and for artifact versions (within the "
13889-
"scope of artifacts)."
13887+
"pipeline runs, pipeline snapshots, pipeline "
13888+
"deployments and artifact versions"
1389013889
)
1389113890

1389213891
# Check for duplicate IDs in any of the scope_ids list

0 commit comments

Comments
 (0)