diff --git a/openfga_sdk/api_client.py b/openfga_sdk/api_client.py index 06edd490..4c521bcf 100644 --- a/openfga_sdk/api_client.py +++ b/openfga_sdk/api_client.py @@ -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 diff --git a/openfga_sdk/sync/api_client.py b/openfga_sdk/sync/api_client.py index 05120813..af0e67e3 100644 --- a/openfga_sdk/sync/api_client.py +++ b/openfga_sdk/sync/api_client.py @@ -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 diff --git a/test/api/open_fga_api_test.py b/test/api/open_fga_api_test.py index 30f95508..a3b9c670 100644 --- a/test/api/open_fga_api_test.py +++ b/test/api/open_fga_api_test.py @@ -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): """ diff --git a/test/sync/open_fga_api_test.py b/test/sync/open_fga_api_test.py index ba0b068f..51931630 100644 --- a/test/sync/open_fga_api_test.py +++ b/test/sync/open_fga_api_test.py @@ -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"""