From 941dc81b23de6a978b68c83da962c4158938b478 Mon Sep 17 00:00:00 2001 From: Michael Schuster Date: Fri, 13 Dec 2024 12:41:14 +0100 Subject: [PATCH] Include user of latest run in pipeline response (#3262) * Include user of latest run in pipeline response * Linting * Fix optional check --- src/zenml/models/v2/core/pipeline.py | 6 +++++- src/zenml/zen_stores/schemas/pipeline_schemas.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/zenml/models/v2/core/pipeline.py b/src/zenml/models/v2/core/pipeline.py index 03a81fbb23..199e9cce95 100644 --- a/src/zenml/models/v2/core/pipeline.py +++ b/src/zenml/models/v2/core/pipeline.py @@ -44,7 +44,7 @@ from zenml.models.v2.core.tag import TagResponse if TYPE_CHECKING: - from zenml.models.v2.core.pipeline_run import PipelineRunResponse + from zenml.models import PipelineRunResponse, UserResponse from zenml.zen_stores.schemas import BaseSchema AnySchema = TypeVar("AnySchema", bound=BaseSchema) @@ -119,6 +119,10 @@ class PipelineResponseMetadata(WorkspaceScopedResponseMetadata): class PipelineResponseResources(WorkspaceScopedResponseResources): """Class for all resource models associated with the pipeline entity.""" + latest_run_user: Optional["UserResponse"] = Field( + default=None, + title="The user that created the latest run of this pipeline.", + ) tags: List[TagResponse] = Field( title="Tags associated with the pipeline.", ) diff --git a/src/zenml/zen_stores/schemas/pipeline_schemas.py b/src/zenml/zen_stores/schemas/pipeline_schemas.py index 1f287720ee..3719a64b20 100644 --- a/src/zenml/zen_stores/schemas/pipeline_schemas.py +++ b/src/zenml/zen_stores/schemas/pipeline_schemas.py @@ -156,7 +156,12 @@ def to_model( resources = None if include_resources: + latest_run_user = self.runs[-1].user if self.runs else None + resources = PipelineResponseResources( + latest_run_user=latest_run_user.to_model() + if latest_run_user + else None, tags=[t.tag.to_model() for t in self.tags], )