Better handling of cookie in python clients#24383
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 9 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
Pull request overview
This PR updates the Python client generator’s cookie auth handling to percent-encode cookie values (while attempting to preserve base64 delimiters), and regenerates the affected Python sample clients to reflect the template change.
Changes:
- Switch cookie auth value handling from quote-wrapping/escaping to
urllib.parse.quote(..., safe='+/=')in the Pythonapi_clienttemplate. - Regenerate multiple Python sample clients (
python,python-httpx,python-httpx-sync,python-aiohttp,python-lazyImports, legacy, and echo-api variants) to match the updated template.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| modules/openapi-generator/src/main/resources/python/api_client.mustache | Updates the cookie auth value formatting logic in the Python generator template. |
| samples/openapi3/client/petstore/python/petstore_api/api_client.py | Regenerated Petstore Python sample with updated cookie auth handling. |
| samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py | Regenerated lazy-imports Petstore Python sample with updated cookie auth handling. |
| samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py | Regenerated httpx Petstore Python sample with updated cookie auth handling. |
| samples/openapi3/client/petstore/python-httpx-sync/petstore_api/api_client.py | Regenerated httpx-sync Petstore Python sample with updated cookie auth handling. |
| samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py | Regenerated aiohttp Petstore Python sample with updated cookie auth handling. |
| samples/client/others/python-legacy-model-dictionaries/legacy_model_dict_client/api_client.py | Regenerated legacy-model-dictionaries Python sample with updated cookie auth handling. |
| samples/client/echo_api/python/openapi_client/api_client.py | Regenerated echo-api Python sample with updated cookie auth handling. |
| samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py | Regenerated echo-api variant Python sample with updated cookie auth handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Account for cookie value containing spaces and special characters, excluding base64 delimiters | ||
| cookie_value = quote(str(auth_setting['value']), safe='+/=') | ||
| headers['Cookie'] += f"{auth_setting['key']}={cookie_value}" |
There was a problem hiding this comment.
All reported issues were addressed across 9 files (changes from recent commits).
Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.
Re-trigger cubic
a follow up pr to #24149
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
Improve cookie handling in Python clients by percent-encoding cookie auth values while preserving RFC 6265–safe characters (including +/=) so base64 and other valid cookies aren’t broken. This prevents malformed Cookie headers when values contain spaces or special characters.
python/api_client.mustacheand regenerate Python samples (python,python-httpx,python-httpx-sync,python-aiohttp,python-lazyImports, legacy).Written for commit 00bf923. Summary will update on new commits.