[python] isolate implicit API clients#24129
Conversation
46d3f88 to
96d76aa
Compare
|
The only red check is @tomplus, could you review the configuration-copy, client-ownership, and @wing328, could you review the option and Python generator scope? |
There was a problem hiding this comment.
2 issues found across 42 files
Note: This PR contains a large number of files. cubic only reviews up to 40 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.
On a pro plan you can use ultrareview for larger PRs.
Re-trigger cubic
96d76aa to
6a61da5
Compare
|
The The I added an inline explanation of that distinction. |
Generated API instances currently share the cached default ApiClient and its Configuration. Mutating credentials, headers, cookies, or transport settings through one implicit API can therefore affect another. Add the default-off useIndependentImplicitClients option. Treat isolation as one ownership contract rather than separate configuration copy and client-cache switches: an API constructed without an explicit or registered default client owns a private client and copied configuration. Its close method and context manager release that client. Explicit and registered clients remain shared and caller-owned. Make Configuration.set_default() copy configuration-owned containers and make get_default_copy() return another copy. Keep process-global logging resources and event-loop-bound transport objects shared, but copy the containers around those objects. Copy proxy-header mappings through their mapping protocol so mutable dictionaries and immutable multidict proxies both produce independent defaults. For aiohttp, preserve connector=None as an explicit request for ClientSession's default connector. Non-None caller-supplied connectors remain caller-owned. Keep the option disabled by default because existing clients may rely on mutating the shared defaults. Rename normalized operation IDs that would overwrite lifecycle methods only when the corresponding lifecycle is generated. Closes OpenAPITools#24124
Regenerate the aiohttp and lazy-import Python clients with copied defaults and independent implicit clients.
6a61da5 to
c059690
Compare
Generated API instances currently share the cached default
ApiClientand its
Configuration. Mutating credentials, headers, cookies, ortransport settings through one implicit API can therefore affect
another.
Add the default-off
useIndependentImplicitClientsoption. Treatisolation as one ownership contract rather than separate configuration
copy and client-cache switches: an API constructed without an explicit
or registered default client owns a private client and copied
configuration. Retain that owned client separately from the public
api_clientattribute, so later reassignment neither transfersownership nor changes what
close()releases. Explicit and registeredclients remain shared and caller-owned.
Make
Configuration.set_default()copy configuration-owned containersand make
get_default_copy()return another copy. Keep process-globallogging resources and stateful transport extension objects shared, but
copy the containers around those objects. Copy proxy-header mappings
through their mapping protocol so mutable dictionaries and immutable
multidict proxies both produce independent defaults.
For aiohttp, preserve
connector=Noneas an explicit request forClientSession's default connector. Non-None caller-suppliedconnectors remain caller-owned.
Keep the option disabled by default because existing clients may rely on
mutating the shared defaults. Resolve operation IDs that conflict with
the generated lifecycle after operations are grouped, so HTTP-info,
streaming, serializer, and HTTPX-sync variants remain unique.
Closes #24124.