Skip to content

Commit b6c6699

Browse files
authored
Add hidden option for run templates (#3500)
* Add hidden option for run templates * Improve filtering and updating via client
1 parent c9153b3 commit b6c6699

File tree

4 files changed

+92
-1
lines changed

4 files changed

+92
-1
lines changed

src/zenml/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3574,6 +3574,7 @@ def list_run_templates(
35743574
updated: Optional[Union[datetime, str]] = None,
35753575
id: Optional[Union[UUID, str]] = None,
35763576
name: Optional[str] = None,
3577+
hidden: Optional[bool] = False,
35773578
tag: Optional[str] = None,
35783579
project: Optional[Union[str, UUID]] = None,
35793580
pipeline_id: Optional[Union[str, UUID]] = None,
@@ -3596,6 +3597,7 @@ def list_run_templates(
35963597
updated: Filter by the last updated date.
35973598
id: Filter by run template ID.
35983599
name: Filter by run template name.
3600+
hidden: Filter by run template hidden status.
35993601
tag: Filter by run template tags.
36003602
project: Filter by project name/ID.
36013603
pipeline_id: Filter by pipeline ID.
@@ -3620,6 +3622,7 @@ def list_run_templates(
36203622
updated=updated,
36213623
id=id,
36223624
name=name,
3625+
hidden=hidden,
36233626
tag=tag,
36243627
project=project,
36253628
pipeline_id=pipeline_id,
@@ -3640,6 +3643,7 @@ def update_run_template(
36403643
name_id_or_prefix: Union[str, UUID],
36413644
name: Optional[str] = None,
36423645
description: Optional[str] = None,
3646+
hidden: Optional[bool] = None,
36433647
add_tags: Optional[List[str]] = None,
36443648
remove_tags: Optional[List[str]] = None,
36453649
project: Optional[Union[str, UUID]] = None,
@@ -3650,6 +3654,7 @@ def update_run_template(
36503654
name_id_or_prefix: Name/ID/ID prefix of the template to update.
36513655
name: The new name of the run template.
36523656
description: The new description of the run template.
3657+
hidden: The new hidden status of the run template.
36533658
add_tags: Tags to add to the run template.
36543659
remove_tags: Tags to remove from the run template.
36553660
project: The project name/ID to filter by.
@@ -3675,6 +3680,7 @@ def update_run_template(
36753680
template_update=RunTemplateUpdate(
36763681
name=name,
36773682
description=description,
3683+
hidden=hidden,
36783684
add_tags=add_tags,
36793685
remove_tags=remove_tags,
36803686
),

src/zenml/models/v2/core/run_template.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class RunTemplateRequest(ProjectScopedRequest):
7979
source_deployment_id: UUID = Field(
8080
title="The deployment that should be the base of the created template."
8181
)
82+
hidden: bool = Field(
83+
default=False,
84+
title="Whether the run template is hidden.",
85+
)
8286
tags: Optional[List[str]] = Field(
8387
default=None,
8488
title="Tags of the run template.",
@@ -101,6 +105,10 @@ class RunTemplateUpdate(BaseUpdate):
101105
title="The description of the run template.",
102106
max_length=TEXT_FIELD_MAX_LENGTH,
103107
)
108+
hidden: Optional[bool] = Field(
109+
default=None,
110+
title="Whether the run template is hidden.",
111+
)
104112
add_tags: Optional[List[str]] = Field(
105113
default=None, title="New tags to add to the run template."
106114
)
@@ -118,6 +126,10 @@ class RunTemplateResponseBody(ProjectScopedResponseBody):
118126
runnable: bool = Field(
119127
title="If a run can be started from the template.",
120128
)
129+
hidden: bool = Field(
130+
default=False,
131+
title="Whether the run template is hidden.",
132+
)
121133
latest_run_id: Optional[UUID] = Field(
122134
default=None,
123135
title="The ID of the latest run of the run template.",
@@ -205,6 +217,15 @@ def runnable(self) -> bool:
205217
"""
206218
return self.get_body().runnable
207219

220+
@property
221+
def hidden(self) -> bool:
222+
"""The `hidden` property.
223+
224+
Returns:
225+
the value of the property.
226+
"""
227+
return self.get_body().hidden
228+
208229
@property
209230
def latest_run_id(self) -> Optional[UUID]:
210231
"""The `latest_run_id` property.
@@ -320,6 +341,7 @@ class RunTemplateFilter(ProjectScopedFilter, TaggableFilter):
320341
"pipeline_id",
321342
"pipeline",
322343
"stack",
344+
"hidden",
323345
]
324346
CUSTOM_SORTING_OPTIONS = [
325347
*ProjectScopedFilter.CUSTOM_SORTING_OPTIONS,
@@ -334,6 +356,10 @@ class RunTemplateFilter(ProjectScopedFilter, TaggableFilter):
334356
default=None,
335357
description="Name of the run template.",
336358
)
359+
hidden: Optional[bool] = Field(
360+
default=None,
361+
description="Whether the run template is hidden.",
362+
)
337363
pipeline_id: Optional[Union[UUID, str]] = Field(
338364
default=None,
339365
description="Pipeline associated with the template.",
@@ -376,7 +402,7 @@ def get_custom_filters(
376402
"""
377403
custom_filters = super().get_custom_filters(table)
378404

379-
from sqlmodel import and_
405+
from sqlmodel import and_, col
380406

381407
from zenml.zen_stores.schemas import (
382408
CodeReferenceSchema,
@@ -386,6 +412,11 @@ def get_custom_filters(
386412
StackSchema,
387413
)
388414

415+
if self.hidden is not None:
416+
custom_filters.append(
417+
col(RunTemplateSchema.hidden).is_(self.hidden)
418+
)
419+
389420
if self.code_repository_id:
390421
code_repo_filter = and_(
391422
RunTemplateSchema.source_deployment_id
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Add hidden option for templates [6611d4bcc95b].
2+
3+
Revision ID: 6611d4bcc95b
4+
Revises: 0.80.1
5+
Create Date: 2025-04-07 10:29:26.130057
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "6611d4bcc95b"
14+
down_revision = "0.80.1"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade() -> None:
20+
"""Upgrade database schema and/or data, creating a new revision."""
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
with op.batch_alter_table("run_template", schema=None) as batch_op:
23+
batch_op.add_column(sa.Column("hidden", sa.Boolean(), nullable=True))
24+
25+
op.execute(
26+
"""
27+
UPDATE `run_template`
28+
SET hidden = 0
29+
"""
30+
)
31+
32+
with op.batch_alter_table("run_template", schema=None) as batch_op:
33+
batch_op.alter_column(
34+
"hidden",
35+
existing_type=sa.Boolean(),
36+
nullable=False,
37+
)
38+
# ### end Alembic commands ###
39+
40+
41+
def downgrade() -> None:
42+
"""Downgrade database schema and/or data back to the previous revision."""
43+
# ### commands auto generated by Alembic - please adjust! ###
44+
with op.batch_alter_table("run_template", schema=None) as batch_op:
45+
batch_op.drop_column("hidden")
46+
47+
# ### end Alembic commands ###

src/zenml/zen_stores/schemas/run_template_schemas.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class RunTemplateSchema(NamedSchema, table=True):
5757
),
5858
)
5959

60+
hidden: bool = Field(
61+
default=False,
62+
title="Whether the run template is hidden.",
63+
)
64+
6065
description: Optional[str] = Field(
6166
sa_column=Column(
6267
String(length=MEDIUMTEXT_MAX_LENGTH).with_variant(
@@ -166,6 +171,7 @@ def from_request(
166171
project_id=request.project,
167172
name=request.name,
168173
description=request.description,
174+
hidden=request.hidden,
169175
source_deployment_id=request.source_deployment_id,
170176
)
171177

@@ -221,6 +227,7 @@ def to_model(
221227
created=self.created,
222228
updated=self.updated,
223229
runnable=runnable,
230+
hidden=self.hidden,
224231
latest_run_id=latest_run.id if latest_run else None,
225232
latest_run_status=latest_run.status if latest_run else None,
226233
)

0 commit comments

Comments
 (0)