diff --git a/src/backend/langflow/services/store/schema.py b/src/backend/langflow/services/store/schema.py index 215b15b91..4f11ad262 100644 --- a/src/backend/langflow/services/store/schema.py +++ b/src/backend/langflow/services/store/schema.py @@ -1,5 +1,5 @@ from datetime import datetime -from pydantic import BaseModel +from pydantic import BaseModel, validator from typing import Optional, List from uuid import UUID @@ -45,9 +45,21 @@ class ListComponentResponse(BaseModel): is_component: Optional[bool] metadata: Optional[dict] user_created: Optional[dict] - tags: Optional[List[TagsIdResponse]] = None + tags: Optional[List[TagResponse]] = None downloads_count: Optional[int] + # tags comes as a TagsIdResponse but we want to return a list of TagResponse + @validator("tags", pre=True) + def tags_to_list(cls, v): + # Check if all values are have id and name + # if so, return v else transform to TagResponse + if all(["id" in tag and "name" in tag for tag in v]): + return v + else: + return [ + TagResponse(**tag.get("tags_id")) for tag in v if tag.get("tags_id") + ] + class DownloadComponentResponse(BaseModel): id: UUID diff --git a/src/backend/langflow/services/store/service.py b/src/backend/langflow/services/store/service.py index 5fcce2860..3015a2729 100644 --- a/src/backend/langflow/services/store/service.py +++ b/src/backend/langflow/services/store/service.py @@ -188,9 +188,9 @@ class StoreService(Service): results = self._get(self.components_url, api_key, params) results_objects = [ListComponentResponse(**component) for component in results] # Flatten the tags - for component in results_objects: - if component.tags: - component.tags = [tags_id.tags_id for tags_id in component.tags] + # for component in results_objects: + # if component.tags: + # component.tags = [tags_id.tags_id for tags_id in component.tags] return results_objects def download(self, api_key: str, component_id: str) -> DownloadComponentResponse: