From d74e50e5cfde2be4b043de41d2cbd32600228404 Mon Sep 17 00:00:00 2001 From: Michael Schuster Date: Fri, 13 Dec 2024 16:04:31 +0100 Subject: [PATCH] Order tags by name --- .../zen_stores/schemas/artifact_schemas.py | 2 + src/zenml/zen_stores/schemas/model_schemas.py | 2 + .../schemas/pipeline_run_schemas.py | 1 + .../zen_stores/schemas/pipeline_schemas.py | 1 + .../schemas/run_template_schemas.py | 1 + src/zenml/zen_stores/schemas/tag_schemas.py | 40 +------------------ 6 files changed, 8 insertions(+), 39 deletions(-) diff --git a/src/zenml/zen_stores/schemas/artifact_schemas.py b/src/zenml/zen_stores/schemas/artifact_schemas.py index 787f99e4a1b..16a24bf1cc1 100644 --- a/src/zenml/zen_stores/schemas/artifact_schemas.py +++ b/src/zenml/zen_stores/schemas/artifact_schemas.py @@ -85,6 +85,7 @@ class ArtifactSchema(NamedSchema, table=True): primaryjoin=f"and_(foreign(TagResourceSchema.resource_type)=='{TaggableResourceTypes.ARTIFACT.value}', foreign(TagResourceSchema.resource_id)==ArtifactSchema.id)", secondary="tag_resource", secondaryjoin="TagSchema.id == foreign(TagResourceSchema.tag_id)", + order_by="TagSchema.name", ), ) @@ -194,6 +195,7 @@ class ArtifactVersionSchema(BaseSchema, RunMetadataInterface, table=True): primaryjoin=f"and_(foreign(TagResourceSchema.resource_type)=='{TaggableResourceTypes.ARTIFACT_VERSION.value}', foreign(TagResourceSchema.resource_id)==ArtifactVersionSchema.id)", secondary="tag_resource", secondaryjoin="TagSchema.id == foreign(TagResourceSchema.tag_id)", + order_by="TagSchema.name", ), ) save_type: str = Field(sa_column=Column(TEXT, nullable=False)) diff --git a/src/zenml/zen_stores/schemas/model_schemas.py b/src/zenml/zen_stores/schemas/model_schemas.py index ddc1a277838..837b27a6c70 100644 --- a/src/zenml/zen_stores/schemas/model_schemas.py +++ b/src/zenml/zen_stores/schemas/model_schemas.py @@ -117,6 +117,7 @@ class ModelSchema(NamedSchema, table=True): primaryjoin=f"and_(foreign(TagResourceSchema.resource_type)=='{TaggableResourceTypes.MODEL.value}', foreign(TagResourceSchema.resource_id)==ModelSchema.id)", secondary="tag_resource", secondaryjoin="TagSchema.id == foreign(TagResourceSchema.tag_id)", + order_by="TagSchema.name", ), ) model_versions: List["ModelVersionSchema"] = Relationship( @@ -301,6 +302,7 @@ class ModelVersionSchema(NamedSchema, RunMetadataInterface, table=True): primaryjoin=f"and_(foreign(TagResourceSchema.resource_type)=='{TaggableResourceTypes.MODEL_VERSION.value}', foreign(TagResourceSchema.resource_id)==ModelVersionSchema.id)", secondary="tag_resource", secondaryjoin="TagSchema.id == foreign(TagResourceSchema.tag_id)", + order_by="TagSchema.name", ), ) diff --git a/src/zenml/zen_stores/schemas/pipeline_run_schemas.py b/src/zenml/zen_stores/schemas/pipeline_run_schemas.py index 5d195b16cd1..7edfcb062e0 100644 --- a/src/zenml/zen_stores/schemas/pipeline_run_schemas.py +++ b/src/zenml/zen_stores/schemas/pipeline_run_schemas.py @@ -217,6 +217,7 @@ class PipelineRunSchema(NamedSchema, RunMetadataInterface, table=True): primaryjoin=f"and_(foreign(TagResourceSchema.resource_type)=='{TaggableResourceTypes.PIPELINE_RUN.value}', foreign(TagResourceSchema.resource_id)==PipelineRunSchema.id)", secondary="tag_resource", secondaryjoin="TagSchema.id == foreign(TagResourceSchema.tag_id)", + order_by="TagSchema.name", ), ) diff --git a/src/zenml/zen_stores/schemas/pipeline_schemas.py b/src/zenml/zen_stores/schemas/pipeline_schemas.py index a3ca7274998..93b4265d76d 100644 --- a/src/zenml/zen_stores/schemas/pipeline_schemas.py +++ b/src/zenml/zen_stores/schemas/pipeline_schemas.py @@ -100,6 +100,7 @@ class PipelineSchema(NamedSchema, table=True): primaryjoin=f"and_(foreign(TagResourceSchema.resource_type)=='{TaggableResourceTypes.PIPELINE.value}', foreign(TagResourceSchema.resource_id)==PipelineSchema.id)", secondary="tag_resource", secondaryjoin="TagSchema.id == foreign(TagResourceSchema.tag_id)", + order_by="TagSchema.name", ), ) diff --git a/src/zenml/zen_stores/schemas/run_template_schemas.py b/src/zenml/zen_stores/schemas/run_template_schemas.py index 688a409987d..26ad4d250b7 100644 --- a/src/zenml/zen_stores/schemas/run_template_schemas.py +++ b/src/zenml/zen_stores/schemas/run_template_schemas.py @@ -115,6 +115,7 @@ class RunTemplateSchema(BaseSchema, table=True): primaryjoin=f"and_(foreign(TagResourceSchema.resource_type)=='{TaggableResourceTypes.RUN_TEMPLATE.value}', foreign(TagResourceSchema.resource_id)==RunTemplateSchema.id)", secondary="tag_resource", secondaryjoin="TagSchema.id == foreign(TagResourceSchema.tag_id)", + order_by="TagSchema.name", ), ) diff --git a/src/zenml/zen_stores/schemas/tag_schemas.py b/src/zenml/zen_stores/schemas/tag_schemas.py index d1e6a0483b4..245fa245992 100644 --- a/src/zenml/zen_stores/schemas/tag_schemas.py +++ b/src/zenml/zen_stores/schemas/tag_schemas.py @@ -14,7 +14,7 @@ """SQLModel implementation of tag tables.""" from datetime import datetime -from typing import TYPE_CHECKING, Any, List +from typing import Any, List from uuid import UUID from sqlalchemy import VARCHAR, Column @@ -33,16 +33,6 @@ from zenml.zen_stores.schemas.base_schemas import BaseSchema, NamedSchema from zenml.zen_stores.schemas.schema_utils import build_foreign_key_field -if TYPE_CHECKING: - from zenml.zen_stores.schemas.artifact_schemas import ( - ArtifactSchema, - ArtifactVersionSchema, - ) - from zenml.zen_stores.schemas.model_schemas import ( - ModelSchema, - ModelVersionSchema, - ) - class TagSchema(NamedSchema, table=True): """SQL Model for tag.""" @@ -133,34 +123,6 @@ class TagResourceSchema(BaseSchema, table=True): tag: "TagSchema" = Relationship(back_populates="links") resource_id: UUID resource_type: str = Field(sa_column=Column(VARCHAR(255), nullable=False)) - artifact: List["ArtifactSchema"] = Relationship( - back_populates="tags", - sa_relationship_kwargs=dict( - primaryjoin=f"and_(TagResourceSchema.resource_type=='{TaggableResourceTypes.ARTIFACT.value}', foreign(TagResourceSchema.resource_id)==ArtifactSchema.id)", - overlaps="tags,model,artifact_version,model_version", - ), - ) - artifact_version: List["ArtifactVersionSchema"] = Relationship( - back_populates="tags", - sa_relationship_kwargs=dict( - primaryjoin=f"and_(TagResourceSchema.resource_type=='{TaggableResourceTypes.ARTIFACT_VERSION.value}', foreign(TagResourceSchema.resource_id)==ArtifactVersionSchema.id)", - overlaps="tags,model,artifact,model_version", - ), - ) - model: List["ModelSchema"] = Relationship( - back_populates="tags", - sa_relationship_kwargs=dict( - primaryjoin=f"and_(TagResourceSchema.resource_type=='{TaggableResourceTypes.MODEL.value}', foreign(TagResourceSchema.resource_id)==ModelSchema.id)", - overlaps="tags,artifact,artifact_version,model_version", - ), - ) - model_version: List["ModelVersionSchema"] = Relationship( - back_populates="tags", - sa_relationship_kwargs=dict( - primaryjoin=f"and_(TagResourceSchema.resource_type=='{TaggableResourceTypes.MODEL_VERSION.value}', foreign(TagResourceSchema.resource_id)==ModelVersionSchema.id)", - overlaps="tags,model,artifact,artifact_version", - ), - ) @classmethod def from_request(cls, request: TagResourceRequest) -> "TagResourceSchema":