Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openfga_sdk/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ async def __call_api(
if _retry_params.max_retry is not None:
max_retry = _retry_params.max_retry
if _retry_params.min_wait_in_ms is not None:
max_retry = _retry_params.min_wait_in_ms
min_wait_in_ms = _retry_params.min_wait_in_ms
if _retry_params.max_wait_in_sec is not None:
max_wait_in_sec = _retry_params.max_wait_in_sec

Expand Down
2 changes: 1 addition & 1 deletion openfga_sdk/sync/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def __call_api(
if _retry_params.max_retry is not None:
max_retry = _retry_params.max_retry
if _retry_params.min_wait_in_ms is not None:
max_retry = _retry_params.min_wait_in_ms
min_wait_in_ms = _retry_params.min_wait_in_ms
if _retry_params.max_wait_in_sec is not None:
max_wait_in_sec = _retry_params.max_wait_in_sec

Expand Down
47 changes: 47 additions & 0 deletions test/api/open_fga_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,53 @@ async def test_500_error(self, mock_request):
mock_request.assert_called()
self.assertEqual(mock_request.call_count, 1)

@patch("asyncio.sleep")
@patch.object(rest.RESTClientObject, "request")
async def test_500_error_per_request_retry_params_does_not_use_min_wait_as_max_retry(
self, mock_request, mock_sleep
):
"""
Per-request RetryParams(max_retry=0, min_wait_in_ms=100) must attempt once.

A copy-paste bug assigned min_wait_in_ms onto max_retry, which turned this
into 101 attempts.
"""
response_body = """
{
"code": "internal_error",
"message": "Internal Server Error"
}
"""
mock_request.side_effect = ServiceException(
http_resp=http_mock_response(response_body, 500)
)

configuration = self.configuration
configuration.store_id = store_id
configuration.retry_params = openfga_sdk.configuration.RetryParams(
max_retry=3, min_wait_in_ms=10
)

async with openfga_sdk.ApiClient(configuration) as api_client:
api_instance = open_fga_api.OpenFgaApi(api_client)
body = CheckRequest(
tuple_key=TupleKey(
object="document:2021-budget",
relation="reader",
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
),
)
with self.assertRaises(ServiceException):
await api_instance.check(
body=body,
_retry_params=openfga_sdk.configuration.RetryParams(
max_retry=0, min_wait_in_ms=100
),
)
mock_request.assert_called()
self.assertEqual(mock_request.call_count, 1)
mock_sleep.assert_not_called()

@patch.object(rest.RESTClientObject, "request")
async def test_500_error_retry(self, mock_request):
"""
Expand Down
47 changes: 47 additions & 0 deletions test/sync/open_fga_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,53 @@ def test_500_error(self, mock_request):
mock_request.assert_called()
self.assertEqual(mock_request.call_count, 1)

@patch("time.sleep")
@patch.object(rest.RESTClientObject, "request")
def test_500_error_per_request_retry_params_does_not_use_min_wait_as_max_retry(
self, mock_request, mock_sleep
):
"""
Per-request RetryParams(max_retry=0, min_wait_in_ms=100) must attempt once.

A copy-paste bug assigned min_wait_in_ms onto max_retry, which turned this
into 101 attempts.
"""
response_body = """
{
"code": "internal_error",
"message": "Internal Server Error"
}
"""
mock_request.side_effect = ServiceException(
http_resp=http_mock_response(response_body, 500)
)

configuration = self.configuration
configuration.store_id = store_id
configuration.retry_params = openfga_sdk.configuration.RetryParams(
max_retry=3, min_wait_in_ms=10
)

with ApiClient(configuration) as api_client:
api_instance = open_fga_api.OpenFgaApi(api_client)
body = CheckRequest(
tuple_key=TupleKey(
object="document:2021-budget",
relation="reader",
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
),
)
with self.assertRaises(ServiceException):
api_instance.check(
body=body,
_retry_params=openfga_sdk.configuration.RetryParams(
max_retry=0, min_wait_in_ms=100
),
)
mock_request.assert_called()
self.assertEqual(mock_request.call_count, 1)
mock_sleep.assert_not_called()

@patch.object(rest.RESTClientObject, "request")
def test_500_error_retry(self, mock_request):
"""Test to ensure 5xx retries are handled properly"""
Expand Down
Loading