Skip to content

Commit b7a7a95

Browse files
authored
fix(Global Tagging): add message field to TagResultsItem (#320)
Signed-off-by: Stefano Roberto Mollica <stefano.mollica@it.ibm.com>
1 parent b9c87e6 commit b7a7a95

4 files changed

Lines changed: 25 additions & 10 deletions

File tree

examples/test_global_tagging_v1_examples.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ def test_attach_tag_example(self):
128128
print('\nattach_tag() result:')
129129
# begin-attach_tag
130130

131+
resource_model = {'resource_id': resource_crn}
132+
131133
tag_results = global_tagging_service.attach_tag(
132-
tag_names=['tag_test_1', 'tag_test_2'], tag_type='user'
134+
resources=[resource_model], tag_names=['tag_test_1', 'tag_test_2'], tag_type='user'
133135
).get_result()
134136

135137
print(json.dumps(tag_results, indent=2))
@@ -148,8 +150,10 @@ def test_detach_tag_example(self):
148150
print('\ndetach_tag() result:')
149151
# begin-detach_tag
150152

153+
resource_model = {'resource_id': resource_crn}
154+
151155
tag_results = global_tagging_service.detach_tag(
152-
tag_names=['tag_test_1', 'tag_test_2'], tag_type='user'
156+
resources=[resource_model], tag_names=['tag_test_1', 'tag_test_2'], tag_type='user'
153157
).get_result()
154158

155159
print(json.dumps(tag_results, indent=2))

ibm_platform_services/global_tagging_v1.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding: utf-8
22

3-
# (C) Copyright IBM Corp. 2025.
3+
# (C) Copyright IBM Corp. 2026.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# IBM OpenAPI SDK Code Generator Version: 3.105.0-3c13b041-20250605-193116
17+
# IBM OpenAPI SDK Code Generator Version: 3.111.0-1bfb72c2-20260206-185521
1818

1919
"""
2020
Manage your tags with the Tagging API in IBM Cloud. You can attach, detach, delete, or
@@ -1628,23 +1628,28 @@ class TagResultsItem:
16281628
:param str resource_id: The CRN or IMS ID of the resource.
16291629
:param bool is_error: (optional) It is `true` if the operation exits with an
16301630
error.
1631+
:param str message: (optional) Error message returned when the operation fails.
16311632
"""
16321633

16331634
def __init__(
16341635
self,
16351636
resource_id: str,
16361637
*,
16371638
is_error: Optional[bool] = None,
1639+
message: Optional[str] = None,
16381640
) -> None:
16391641
"""
16401642
Initialize a TagResultsItem object.
16411643
16421644
:param str resource_id: The CRN or IMS ID of the resource.
16431645
:param bool is_error: (optional) It is `true` if the operation exits with
16441646
an error.
1647+
:param str message: (optional) Error message returned when the operation
1648+
fails.
16451649
"""
16461650
self.resource_id = resource_id
16471651
self.is_error = is_error
1652+
self.message = message
16481653

16491654
@classmethod
16501655
def from_dict(cls, _dict: Dict) -> 'TagResultsItem':
@@ -1656,6 +1661,8 @@ def from_dict(cls, _dict: Dict) -> 'TagResultsItem':
16561661
raise ValueError('Required property \'resource_id\' not present in TagResultsItem JSON')
16571662
if (is_error := _dict.get('is_error')) is not None:
16581663
args['is_error'] = is_error
1664+
if (message := _dict.get('message')) is not None:
1665+
args['message'] = message
16591666
return cls(**args)
16601667

16611668
@classmethod
@@ -1670,6 +1677,8 @@ def to_dict(self) -> Dict:
16701677
_dict['resource_id'] = self.resource_id
16711678
if hasattr(self, 'is_error') and self.is_error is not None:
16721679
_dict['is_error'] = self.is_error
1680+
if hasattr(self, 'message') and self.message is not None:
1681+
_dict['message'] = self.message
16731682
return _dict
16741683

16751684
def _to_dict(self):

test/integration/test_global_tagging_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def test_delete_tag_user(self):
329329
print('\ndelete_tag(user) result: ', json.dumps(delete_tag_results.to_dict(), indent=2))
330330

331331
for item in delete_tag_results.results:
332-
assert item.is_error is False
332+
assert item.is_error is True # tags are already deleted at detach time if not attached to any resource
333333

334334
@needscredentials
335335
def test_delete_tag_access(self):

test/unit/test_global_tagging_v1.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# (C) Copyright IBM Corp. 2025.
2+
# (C) Copyright IBM Corp. 2026.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -573,7 +573,7 @@ def test_attach_tag_all_params(self):
573573
"""
574574
# Set up mock
575575
url = preprocess_url('/v3/tags/attach')
576-
mock_response = '{"results": [{"resource_id": "resource_id", "is_error": true}]}'
576+
mock_response = '{"results": [{"resource_id": "resource_id", "is_error": true, "message": "message"}]}'
577577
responses.add(
578578
responses.POST,
579579
url,
@@ -651,7 +651,7 @@ def test_attach_tag_required_params(self):
651651
"""
652652
# Set up mock
653653
url = preprocess_url('/v3/tags/attach')
654-
mock_response = '{"results": [{"resource_id": "resource_id", "is_error": true}]}'
654+
mock_response = '{"results": [{"resource_id": "resource_id", "is_error": true, "message": "message"}]}'
655655
responses.add(
656656
responses.POST,
657657
url,
@@ -716,7 +716,7 @@ def test_detach_tag_all_params(self):
716716
"""
717717
# Set up mock
718718
url = preprocess_url('/v3/tags/detach')
719-
mock_response = '{"results": [{"resource_id": "resource_id", "is_error": true}]}'
719+
mock_response = '{"results": [{"resource_id": "resource_id", "is_error": true, "message": "message"}]}'
720720
responses.add(
721721
responses.POST,
722722
url,
@@ -788,7 +788,7 @@ def test_detach_tag_required_params(self):
788788
"""
789789
# Set up mock
790790
url = preprocess_url('/v3/tags/detach')
791-
mock_response = '{"results": [{"resource_id": "resource_id", "is_error": true}]}'
791+
mock_response = '{"results": [{"resource_id": "resource_id", "is_error": true, "message": "message"}]}'
792792
responses.add(
793793
responses.POST,
794794
url,
@@ -1220,6 +1220,7 @@ def test_tag_results_serialization(self):
12201220
'crn:v1:staging:public:resource-controller::a/5c2ac0d93c69e82c6c9c7c78dc4beda3::resource-group:1c061f4485b34360a8f8ee049880dc13'
12211221
)
12221222
tag_results_item_model['is_error'] = False
1223+
tag_results_item_model['message'] = 'testString'
12231224

12241225
# Construct a json representation of a TagResults model
12251226
tag_results_model_json = {}
@@ -1255,6 +1256,7 @@ def test_tag_results_item_serialization(self):
12551256
tag_results_item_model_json = {}
12561257
tag_results_item_model_json['resource_id'] = 'testString'
12571258
tag_results_item_model_json['is_error'] = True
1259+
tag_results_item_model_json['message'] = 'testString'
12581260

12591261
# Construct a model instance of TagResultsItem by calling from_dict on the json representation
12601262
tag_results_item_model = TagResultsItem.from_dict(tag_results_item_model_json)

0 commit comments

Comments
 (0)