feat(python): enhance retry configuration in REST client#22867
feat(python): enhance retry configuration in REST client#22867wing328 merged 3 commits intoOpenAPITools:masterfrom
Conversation
|
as per PR template, mentioning the python team |
|
thanks for the pr please follow step 3 to update the samples |
modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache
Show resolved
Hide resolved
Updated the retry parameter in the Configuration class to support different types based on the library used (urllib3 or asyncio). Adjusted the RESTClientObject to handle the new retry configuration, allowing for more flexible retry options. This change improves the handling of retries in API requests, ensuring compatibility with various retry strategies.
185b381 to
54c5877
Compare
done |
modules/openapi-generator/src/main/resources/python/configuration.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/python/configuration.mustache
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
1 issue found across 7 files (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py">
<violation number="1" location="samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py:170">
P3: Docstring for retries references aiohttp_retry types in a python-httpx client, which is misleading and inconsistent with this sample’s HTTP library.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| :param ssl_ca_cert: str - the path to a file of concatenated CA certificates | ||
| in PEM format. | ||
| :param retries: Number of retries for API requests. | ||
| :param retries: int | aiohttp_retry.RetryOptionsBase - Retry configuration. |
There was a problem hiding this comment.
P3: Docstring for retries references aiohttp_retry types in a python-httpx client, which is misleading and inconsistent with this sample’s HTTP library.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py, line 170:
<comment>Docstring for retries references aiohttp_retry types in a python-httpx client, which is misleading and inconsistent with this sample’s HTTP library.</comment>
<file context>
@@ -167,9 +167,7 @@ class Configuration:
- :param retries: Retry config; type depends on library:
- * urllib3: int | urllib3.util.retry.Retry
- * asyncio: int | aiohttp_retry.RetryOptionsBase
+ :param retries: int | aiohttp_retry.RetryOptionsBase - Retry configuration.
:param ca_cert_data: verify the peer using concatenated CA certificate data
in PEM (str) or DER (bytes) format.
</file context>
There was a problem hiding this comment.
since class based retries are only supported by the urllib3 and asyncio generators, but not httpx, tornado, etc. this might be misleading, as setting the class on retries has no effect on those. However before this PR the retries config option had no effect on those generators anyways
Description
Updated the
retriesparameter in the Python clientConfigurationso its type depends on the HTTP library:Retry | int | None— passed through to the pool as connection pool kwargs (key_retries).int | aiohttp_retry.RetryOptionsBase | None—intis turned intoExponentialRetry; otherwise the given RetryOptionsBase instance is used.Type annotation:
Optional[Union[int, Any]]. Noisinstancechecks in the urllib3 client as it does not require one; retries are passed through as-is.Implements #17011
Other python generators, like httpx, tornado, etc. are out of scope as they either have no native retry mechanism or no maintained third party libraries
Checklist (unchanged from your template):
Summary by cubic
Make the Python client's retry config transport-aware. Configuration.retries now accepts int or library-specific options for urllib3 and asyncio, enabling custom retry strategies and addressing #17011.
Written for commit 28850ba. Summary will update on new commits.