Skip to content

Commit

Permalink
Update waiters to handle expected boolean values when matching errors (
Browse files Browse the repository at this point in the history
…boto#3220)

* Handle expected boolean values for waiter error matcher

* Add changes entry
  • Loading branch information
jonathan343 authored and hswong3i committed Jul 19, 2024
1 parent e4154a6 commit 4f5bc40
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-Waiter-88466.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "Waiter",
"description": "Update waiters to handle expected boolean values when matching errors (`boto/botocore#3220 <https://github.com/boto/botocore/issues/3220>`__)"
}
10 changes: 9 additions & 1 deletion botocore/waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,15 @@ def acceptor_matches(response):
# response. So response is still a dictionary, and in the case
# of an error response will contain the "Error" and
# "ResponseMetadata" key.
return response.get("Error", {}).get("Code", "") == expected
# When expected is True, accept any error code.
# When expected is False, check if any errors were encountered.
# Otherwise, check for a specific AWS error code.
if expected is True:
return "Error" in response and "Code" in response["Error"]
elif expected is False:
return "Error" not in response
else:
return response.get("Error", {}).get("Code", "") == expected

return acceptor_matches

Expand Down
32 changes: 32 additions & 0 deletions tests/unit/test_waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,38 @@ def test_single_waiter_supports_error(self):
success_acceptor({'Error': {'Code': 'DoesNotExistErorr'}})
)

def test_single_waiter_supports_no_error(self):
single_waiter = {
'acceptors': [
{
'state': 'success',
'matcher': 'error',
'expected': False,
}
],
}
single_waiter.update(self.boiler_plate_config)
config = SingleWaiterConfig(single_waiter)
success_acceptor = config.acceptors[0].matcher_func
self.assertTrue(success_acceptor({}))
self.assertFalse(success_acceptor({'Error': {'Code': 'ExampleError'}}))

def test_single_waiter_supports_any_error(self):
single_waiter = {
'acceptors': [
{
'state': 'success',
'matcher': 'error',
'expected': True,
}
],
}
single_waiter.update(self.boiler_plate_config)
config = SingleWaiterConfig(single_waiter)
success_acceptor = config.acceptors[0].matcher_func
self.assertTrue(success_acceptor({'Error': {'Code': 'ExampleError1'}}))
self.assertTrue(success_acceptor({'Error': {'Code': 'ExampleError2'}}))

def test_unknown_matcher(self):
unknown_type = 'arbitrary_type'
single_waiter = {
Expand Down

0 comments on commit 4f5bc40

Please sign in to comment.