From 56c6802ad6426086e9ef2e0e8c3023bb5bbf2954 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Thu, 7 Dec 2023 12:28:02 +0000 Subject: [PATCH] Make payload optional again for create tag API Before https://github.com/galaxyproject/galaxy/pull/17064 it was possible to create a tag by simply making a POST request like `/api/histories/911dde3ddb677bcd/tags/tag1` , this restores the previous behaviour. Fix BioBlend test failure: https://github.com/galaxyproject/bioblend/actions/runs/7094150509/job/19308900670#step:10:3029 --- lib/galaxy/schema/item_tags.py | 4 ++-- lib/galaxy/webapps/galaxy/api/item_tags.py | 4 +++- lib/galaxy_test/api/test_item_tags.py | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/schema/item_tags.py b/lib/galaxy/schema/item_tags.py index 6458241717c9..1237e42f01dc 100644 --- a/lib/galaxy/schema/item_tags.py +++ b/lib/galaxy/schema/item_tags.py @@ -42,7 +42,7 @@ class ItemTagsListResponse(Model): class ItemTagsCreatePayload(Model): """Payload schema for creating an item tag.""" - value: str = Field( - Required, + value: Optional[str] = Field( + None, title="value of the item tag", ) diff --git a/lib/galaxy/webapps/galaxy/api/item_tags.py b/lib/galaxy/webapps/galaxy/api/item_tags.py index 7b7f7fb65389..a32805ac4d49 100644 --- a/lib/galaxy/webapps/galaxy/api/item_tags.py +++ b/lib/galaxy/webapps/galaxy/api/item_tags.py @@ -72,8 +72,10 @@ def create( trans: ProvidesAppContext = DependsOnTrans, item_id: DecodedDatabaseIdField = Path(..., title="Item ID", alias=tagged_item_id), tag_name: str = Path(..., title="Tag Name"), - payload: ItemTagsCreatePayload = Body(...), + payload: ItemTagsCreatePayload = Body(None), ) -> ItemTagsResponse: + if payload is None: + payload = ItemTagsCreatePayload() return self.manager.create(trans, tagged_item_class, item_id, tag_name, payload) @router.put( diff --git a/lib/galaxy_test/api/test_item_tags.py b/lib/galaxy_test/api/test_item_tags.py index 57c4c53bd9a9..3bf856126c8d 100644 --- a/lib/galaxy_test/api/test_item_tags.py +++ b/lib/galaxy_test/api/test_item_tags.py @@ -1,3 +1,8 @@ +from typing import ( + Any, + Dict, +) + from galaxy_test.base.populators import ( DatasetCollectionPopulator, DatasetPopulator, @@ -125,7 +130,7 @@ def _test_delete_tag(self, prefix): def _create_valid_tag(self, prefix: str): url = f"{prefix}/tags/awesometagname" - tag_data = dict(value="awesometagvalue") + tag_data: Dict[str, Any] = {} # Can also be dict(value="awesometagvalue") response = self._post(url, data=tag_data, json=True) return response